akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(){
int N,H;
scanf("%d %d",&H,&N);
  if((H>N)&&(H%N!=0)){
  printf("%d",H/N+1);
  }else if(H>N){
  printf("%d",H/N);
  }
  else{
  printf("1");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define lint long long
#define MAX 100000
int gcd(lint a, lint b) {
	if (min(a, b) == 0) return max(a, b);
	if (min(a, b) == 1)return 1;
	if (a > b) return gcd(b, a%b);
	if (b > a) return gcd(a, b%a);
}
int main() {
	
	lint N, X; cin >> N >> X;
	vector<lint> dist(N);
	for (lint i = 0; i < N; i++)
	{
		lint x;
		cin >> x;
		dist[i] = abs(x - X);

	}
	lint D = dist[0];
	for (lint i = 0; i < N-1; i++)
	{
		D = gcd(D, dist[i+1]);
	}
	cout << D << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<tuple>
using namespace std;
int main(){
    int n,m,p,y;
    cin>>n>>m;
    vector<tuple<int,int,int,int>>d(m);
    for(int i=0;i<m;i++){cin>>p>>y;get<0>(d[i])=p,get<1>(d[i])=y,get<2>(d[i])=i;}
    sort(d.begin(),d.end(),[](const tuple<int,int,int,int>& x,const tuple<int,int,int,int>& y){return get<0>(x)==get<0>(y)?get<1>(x)<get<1>(y):get<0>(x)<get<0>(y);});
    for(int i=0,t=0,c=0;i<m;get<3>(d[i])=++c,i++)if(t!=get<0>(d[i]))t=get<0>(d[i]),c=0;    
    sort(d.begin(),d.end(),[](const tuple<int,int,int,int>& x,const tuple<int,int,int,int>& y){return get<2>(x)<get<2>(y);});
    for(int i=0;i<m;i++)cout<<setw(6)<<setfill('0')<<get<0>(d[i])<<setw(6)<<setfill('0')<<get<3>(d[i])<<endl;
    return 0;
}

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

#define rep(i,start,end) for(int i=start;i<(int)(end);i++)
#define rrep(i,start,end) for(int i=start-1;i>=(int)(end);i--)
#define each(it,v) for(auto &it : v)
#define all(v) (v).begin(),(v).end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using vpii = vector<Pii>;
using vpll = vector<Pll>;

const ll mod=1e9+7;
const int intINF=INT_MAX;
const ll  longINF=LONG_LONG_MAX;

char maze[22][22];
int h,w;
int di[22][22][22][22];


main()
{
        cin>>h>>w;
        rep(i,0,h)rep(j,0,w)cin>>maze[i][j];
        rep(a,0,h)rep(b,0,w)rep(c,0,h)rep(d,0,w)
        {
                if(maze[a][b]=='.'&&maze[c][d]=='.')
                {
                        if(a==c&&b==d)di[a][b][c][d]=0;
                        else if(abs(a-c)==1&&b==d)di[a][b][c][d]=1;
                        else if(a==c&&abs(b-d)==1)di[a][b][c][d]=1;
                        else di[a][b][c][d]=1010;
                }else
                {
                        di[a][b][c][d]=-1;
                }
        }


        rep(i,0,h)
        {
                rep(j,0,w)
                {
                        rep(a,0,h)rep(b,0,w)rep(c,0,h)rep(d,0,w)
                        {
                                if(maze[a][b]=='.'&&maze[c][d]=='.'&&maze[i][j]=='.')
                                {
                                        di[a][b][c][d]=min(di[a][b][c][d],di[a][b][i][j]+di[i][j][c][d]);
                                        //printf("di[%d][%d][%d][%d] is %4d (i,j)=(%d %d)\n",a,b,c,d,di[a][b][c][d],i,j);
                                }
                        }
                }
        }

        int ans=0;
        int sx,sy,gx,gy;
        rep(a,0,h)rep(b,0,w)rep(c,0,h)rep(d,0,w)
        {
                if(ans<di[a][b][c][d])
                {
                        ans=di[a][b][c][d];
                        sx=a; sy=b; gx=c; gy=d;
                }
        }

        cout<<ans<<endl;
        //printf("{%d %d},{%d %d}\n",sx,sy,gx,gy);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const ll inf = 1e18;
const int MAX = 100005;

int dp[MAX];

int main() {
    int n; cin >> n;
    rep(i,MAX) dp[i] = i;
    for (int i = 6; i <= n; i *= 6) {
        rep(j,MAX) {
            if (j-i < 0) continue;
            chmin(dp[j],dp[j-i]+1);
        }
    }
    for (int i = 9; i <= n; i *= 9) {
        rep(j,MAX) {
            if (j-i < 0) continue;
            chmin(dp[j],dp[j-i]+1);
        }
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#define FOR(idx, begin, end) for(int idx = (int)(begin); idx < (int)(end); ++idx)

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
typedef long long lint;

const int MOD = 1000000007;
const int INF = 1000000000;
const double EPS = 1e-9;


int main() {

	cin.tie(0);

	int N, K;
	cin >> N >> K;

	string S;
	cin >> S;

	int cnt = 1;
	vector<int> set1,set0;

	FOR(i, 1, N) {
		if (S[i] == S[i - 1]) {
			cnt++;
		}
		else {
			if (S[i] == '0')	set1.emplace_back(cnt);
			else set0.emplace_back(cnt);
			cnt = 1;
		}
	}
	if (S[N - 1] == '1')	set1.emplace_back(cnt);
	else set0.emplace_back(cnt);

	int ans = 0, tmp = 0,offset = 1;

	if (S[0] == '1') offset = 0;

	cnt = 0;
	if (set0.size() <= K) {
		FOR(i, 0, set1.size()) ans += set1[i];
		FOR(i, 0, set0.size()) ans += set0[i];
	}
	else {
		while (K + cnt <= set0.size()) {
			FOR(i, ((cnt - offset) > 0 ? (cnt - offset) : 0), K + cnt + 1 - offset > set1.size() ? set1.size() : K + cnt + 1 - offset) tmp += set1[i];
			FOR(i, cnt, K + cnt) tmp += set0[i];
			ans = ans > tmp ? ans : tmp;
			tmp = 0;
			cnt++;
		}
	}

	cout << ans;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int>vec;
signed Lunlun(int n,int A) {
    vec.push_back(A);
    if(n == 10) {
        return 0;
    }
    if(A%10 != 0 && A%10 != 9) {
        Lunlun(n+1,A*10+A%10+1);
        Lunlun(n+1,A*10+A%10-1);
        Lunlun(n+1,A*10+A%10);
        return 0;
    }
    else if(A%10 == 0) {
        Lunlun(n+1,A*10+1);
        Lunlun(n+1,A*10);
        return 0;
    }
    else {
        Lunlun(n+1,A*10+8);
        Lunlun(n+1,A*10+9);
        return 0;
    }
}
signed main() {
    int K;
    cin >> K;
    for(int i = 1; i < 10; i++) {
        Lunlun(0,i);
    }
    sort(vec.begin(),vec.end());
    cout << vec[K-1] << endl;
}


Measured memory_bytes: 11600
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}



int main(){
    int n; cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int q; cin >> q;
    for(int i = 0; i < q; i++){
        int b,e,t; cin >> b >> e >> t;
        for(int k = 0; k < e-b; k++){
            swap(a[b+k],a[t+k]);
        }
    }
    for(int i = 0; i < n; i++){
        if (i != n-1) cout << a[i] << " ";
        else cout << a[i] << endl;
    }
}
  




Measured memory_bytes: 3108
#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#pragma endregion
//-------------------

int main(){
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
    int n; cin >> n;
    ll d; cin >> d;
    int ans = 0;
    rep(i,n) {
        ll x,y; cin >> x >> y;
        if(x*x + y*y <= d*d) ans ++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

/**
 * Membership Management
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == 0) break;

			Map<String, Set<String>> groups = new HashMap<>();
			String first = "";

			for (int i = 0; i < n; i++) {
				words = br.readLine().replaceAll("\\.", "").split("[:,]");
				groups.put(words[0], new HashSet<>());
				for (int j = 1; j < words.length; j++) {
					groups.get(words[0]).add(words[j]);
				}
				if (i == 0) first = words[0];
			}

			//solve
			boolean changed;
			do {
				changed = false;
				for (String group : groups.keySet()) {
					if (!group.equals(first) && groups.get(first).contains(group)) {
						groups.get(first).remove(group);
						groups.get(first).addAll(groups.get(group));
						changed = true;
					}
				}
			} while (changed);

			System.out.println(groups.get(first).size());
		}
	}
}

Measured memory_bytes: 38824
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	char c;
	for (int i = 0; i < 3; ++i) {
		scanf(" %c", &c);
		if (c == '7') {
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fe first
#define se second
#define pii pair<int,int>
#define PI  3.14159265358979323846

int cost,sum,tot;

void solve()
{ int a,b;
	cin>>a>>b;
	if(b%a==0)
		cout<<a+b;
	else
	   cout<<b-a;
}


int main()
{ cool;
	 int t=1;
	 while(t--)
        { solve();
        }

        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
bool visited[1000000 + 2] = { 0, };
bool checked[1000000 + 2] = { 0, };
bool scored[1000000 + 2] = { 0, };

int main()
{
	int N, cnt = 0;
	cin >> N;
	vector<int>v(N);
	for (auto&i : v)cin >> i;
	sort(v.begin(), v.end());

	int last = -1;
	for (auto i : v)
	{
		if (i == last)
		{
			if (!checked[i]&&scored[i])
			{
				cnt--;
				checked[i] = true;
			}
			continue;
		}
		last = i;

		bool find = false;
		for (int j = 1; j <= sqrt(i) + 1; j++)
		{
			if (i%j == 0 && (visited[j] || visited[i / j]))find = true;
		}
		if (!find)
		{
			cnt++;
			scored[i] = true;
		}
		visited[i] = true;
	}
	cout << cnt;
}

Measured memory_bytes: 6944
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <list>
#include <math.h>
#include <vector>
#include <algorithm>
#include<iomanip>
#include <unordered_map> 
#include <queue>
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
 
#define MOD 1000000007
 
 
int main() {
  
  string S;
  
  cin >> S;
  
  int len = S.length();
  int cnt = 0;
  
  for (int i = 0; i < (len / 2); i++) {
    if (S[i] == S[len - i - 1]) {
      
    }
    else {
       cnt++;
    }
  }
  
  cout << cnt;
 
  //for float, double precision
  //cout << std::fixed << setprecision(15);
  return 0;
 
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    const int inf=(1<<30);
    int n,m;
    cin >> n >> m;
    int r1,c1,r2,c2;
    cin >> r1 >> c1 >> r2 >> c2;
    vector<string> s(n+1);
    for(int i=1;i<=n;i++)
    {
        cin >> s[i];
        s[i]="$"+s[i];
    }
    auto in=[&](int r,int c)->bool{return (1<=r&&r<=n&&1<=c&&c<=m);};
    priority_queue<array<int,3>,vector<array<int,3>>,greater<array<int,3>>> q;
    vector<vector<int>> d(n+1,vector<int>(m+1,inf));
    d[r1][c1]=0;
    q.push({0,r1,c1});
    while(!q.empty())
    {
        auto [dx,r,c]=q.top();
        q.pop();
        if(d[r][c]<dx) continue;
        for(int i=-2;i<=2;i++)
        {
            for(int j=-2;j<=2;j++)
            {
                if(in(r+i,c+j)==0||(i==0&&j==0)) continue;
                int x=abs(i)+abs(j);
                if(x==1&&s[r+i][c+j]=='.'&&d[r][c]<d[r+i][c+j])
                {
                    d[r+i][c+j]=d[r][c];
                    q.push({d[r+i][j+c],r+i,j+c});
                }
                else if(s[r+i][c+j]=='.'&&d[r][c]+1<d[r+i][c+j])
                {
                    d[r+i][c+j]=d[r][c]+1;
                    q.push({d[r+i][j+c],r+i,j+c});
                }
            }
        }
    }
    if(d[r2][c2]!=inf) cout << d[r2][c2] << "\n";
    else cout << "-1\n";
    return 0;
}


Measured memory_bytes: 8552
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <iomanip>
using namespace std;

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

void print_vector(vector<ll> vt){
    for(auto v: vt){
        cout << v;
    }
    cout << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<P> X(N);
    for(int i=0; i<N; i++){
        cin >> X[i].first;
        X[i].second=i;
    }
    sort(X.begin(), X.end());
    vector<ll> ans(N);
    for(int i=0; i<N; i++){
        if(i<N/2){
            ans[X[i].second]=X[N/2].first;
        }else{
            ans[X[i].second]=X[N/2-1].first;
        }
    }
    for(int i=0; i<N; i++){
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 6912
import sys
import collections
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    s = []
    for _ in range(n):
        s.append(input())
    s = collections.Counter(s)
    print('AC x {}'.format(s['AC']))
    print('WA x {}'.format(s['WA']))
    print('TLE x {}'.format(s['TLE']))
    print('RE x {}'.format(s['RE']))
    
if __name__ == '__main__':
    main()

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

using namespace std;

typedef long long ll;

const int mod = 1e9+7; 

int main(){
	int a,b;
	cin >> a >> b;
	int t = a+b;
	if(a%3==0 || b%3==0 || t%3==0) cout << "Possible\n";
	else cout << "Impossible\n";

	return 0;
} 

Measured memory_bytes: 256
def main():
    n = int(input())
    a_list = []
    for i in range(n):
        a = int(input())
        #[タグ、値]
        a_list.append([i,a])

    ans = sorted(a_list, key=lambda x:x[1])
    #print(ans)

    #print("-"*75)
    for i in range(n):
        #if 値 == max(ans)
        if a_list[i][1] == ans[-1][1]:
            #ansの最後から二番目の値
            print(ans[-2][1])
        else:
            print(ans[-1][1])

main()


Measured memory_bytes: 43044
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;
import static java.util.Arrays.fill;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void solve() throws Exception {
		int n = scanInt();
		long k = scanLong();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scanInt();
		}
		int p[] = new int[200001];
		for (int i = n - 1; i >= 0; i--) {
			p[a[i]] = i + n;
		}
		int next[] = new int[n];
		for (int i = n - 1; i >= 0; i--) {
			next[i] = p[a[i]];
			p[a[i]] = i;
		}
		long pos[] = new long[n];
		fill(pos, -1);
		long curPos = 0, maxPos = k * n;
		int curI = 0;
		while (curPos < maxPos) {
			if (pos[curI] >= 0) {
				long jump = curPos - pos[curI];
				if (curPos + jump <= maxPos) {
					curPos += (maxPos - curPos) / jump * jump;
				}
				if (curPos >= maxPos) {
					break;
				}
			}
			pos[curI] = curPos;
			long nextPos = curPos + (next[curI] - curI + 1);
			if (nextPos > maxPos) {
				out.print(a[curI] + " ");
				++curPos;
				curI = (curI + 1) % n;
			} else {
				curPos = nextPos;
				curI = (next[curI] + 1) % n;
			}
		}
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 50448
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORX(i, a, b, x) for (int i = (a); i <= (b); i+=x)
#define debug(x) cerr << #x << " is= " << x << endl; //use for debugging
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 5] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
 
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
 
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define mp(a,b) make_pair(a,b)
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long int
#define vi         vector<int>
#define vll        vector<ll>
#define vpii       vector<pair<int,int>>
#define vov        vector<vector<int>> 
#define pr         pair<ll,ll>
#define vpll       vector<pair<ll,ll>>
#define all(v)     v.begin(),v.end()
#define rall(v)    v.rbegin(),v.rend()  //reverse of above;
#define sz(container) int((container).sz())
#define cut(x) {cout<<x<<"\n"; return 0;}
#define setprec(x) cout << fixed << showpoint << setprecision(8)<<x<<endl;
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define time cout << clock() / double(CLOCKS_PER_SEC) << endl;
#define endl "\n"
//#define mod 1000000007
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
//*s.find_by_order(1);
//s.order_of_key() ->number of elements strictly smaller then our item;
//st.rbegin()->second; last element in set
//st.erase(prev(st.end())); delete last element in set;
const int N=1e5+5;
ll mod=1000000007;
ll powm(ll a,ll b)
{
    ll r=a%mod,ans=1;
    while(b>0)
    {
        if(b%2==1)
        ans=(ans*r)%mod;
        r=(r*r)%mod;
        b>>=1;
    }
    return ans;
}
int main()
{
  fast_io;
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  ll n,ans;
  cin>>n;
  if(n==1) cut(0);
  ans=(powm(10,n)+powm(8,n)-2*powm(9,n)+3*mod)%mod;
  cout<<ans;
}

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

int main(){
	ll a,b,c; cin>>a>>b>>c;
	ll cnt=0;
	while(1){
		if(a%2==1||b%2==1||c%2==1){cout<<cnt<<endl; return 0;}
		else if(a==b&&b==c){cout<<-1<<endl; return 0;}
		else{
			cnt++;
			ll ta,tb,tc;
			ta=b/2+c/2; tb=a/2+c/2; tc=a/2+b/2;
			a=ta; b=tb; c=tc;
		}
	}
}

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

vector<int> forintinput(int n) {
	vector<int> x(100000);
	for(int i = 0;i < n;i++) cin >> x[i];
	return x;
}
int main(){
	int n;
	cin >> n;
	cout << (n+2-1) / 2 << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>
#include <math.h>
#include <set>

#define inf -1e18
#define sz 1e5
using ll = long long int;
using namespace std;

int main() {
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll temp;
    ll max=inf;
    temp=a*c;
    max=max>temp?max:temp;
temp=a*d;
    max=max>temp?max:temp;
    temp=b*c;
    max=max>temp?max:temp;
    temp=b*d;
    max=max>temp?max:temp;
cout<<max<<endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll n; cin >> n;

    vector<ll> p(n);
    for (ll i = 0; i < n; ++i) {
        cin >> p[i];
    }

    ll mi = p[0];

    ll ans = 0;

    for (ll i = 0; i < n; ++i) {
        if (mi >= p[i]) {
            ++ans;
        }

        mi = min(mi, p[i]);
    }

    cout << ans << endl;
}

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

int main() {
  long long N;
  cin >> N;
  long long a[5];
  for (int i = 0; i < 5; ++i) {
    cin >> a[i];
  }

  long long min=10000000000000000;
  long long minnumber;

  for (int i = 0; i < 5; ++i) {
    if(min>a[i]){
      min = a[i];
      minnumber = i;
    }
  }

  long long count = 4 + (N+(min-1))/min;

  cout << count << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

#include <vector>

using namespace std;

int main()
{
    int m,n;
    int min, max;
    long long sum;
    
    cin >> n ;

    vector<int> arrayInt(0);

    for (int k = 0; k < n; k++) {
        cin >> m;
        arrayInt.push_back(m);
    }

    sum = 0;
    for (int j = 0; j < n; j++) {
        sum = sum + arrayInt[j];
    }
    
    max = arrayInt[0];
    for (int j = 1; j < n; j++) {
        if (max <= arrayInt[j]) {
            max = arrayInt[j];
        }
    }

    min = arrayInt[0];
    for (int j = 1; j < n; j++) {
        if (min >= arrayInt[j]) {
            min = arrayInt[j];
        }
    }
    
    cout << min << " " << max << " " << sum << endl;

    return 0;
}


Measured memory_bytes: 3244
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

int main(int argv, char **argc){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n;
    cin >> n;
    vector<pair<int,int>> a(n);
    for(int i = 0;i < n; ++i){
        cin >> a[i].first >> a[i].second;
    }
    auto cmp = [](pair<int,int> one, pair<int,int> two) -> bool {
        return one.second < two.second;
    };
    sort(a.begin(), a.end(), cmp);
    ll s = 0;
    for(int i = 0; i < n; ++i){
        s += a[i].first;
        if(s > a[i].second){
            cout << "No\n"; return 0;
        }
    }
    cout << "Yes\n";
}


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

int main() {
	int n,num;
	cin >> n;
	int* ary = new int[n];
	int i;
	for (i = 0; i < n; i++) {
		cin >> num;
		ary[i] = num;
	}
	for (i = n - 1; i > 0; i--) {
		cout << ary[i] << " ";
	}
	cout << ary[i] << endl;
	delete[] ary;
	return 0;
}

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

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

  vector<int> a(n+5);
  vector<int> b(n+5);
  
  int ans = 0;

  for(int i=1;i<n;i++){
    cin >>b.at(i);
  }

  for(int i=1;i<=n-1;i++){
    if(i==1) a.at(i) = b.at(i);

    if(i != 1) a.at(i) = min(b.at(i-1), b.at(i));

    if(i == n-1) a.at(n) = b.at(n-1);
  }
 

  for(int i=1;i<=n;i++){
    ans += a.at(i);
  }
  

  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits//stdc++.h>
using namespace std;
int main(){
    int a[4];
    cin >>a[0]>>a[1]>>a[2]>>a[3];
    sort(a,a+4);
    if(a[0]==a[1]&&a[2]==a[3]) cout << "yes" << endl;
    else cout << "no" << endl;
}


Measured memory_bytes: 3172
#include <stdio.h>  
#include <string.h>  
   
int main()  
{  
    char str[105];  
    scanf("%s",str);
    char ch = ' ';  
      
    
    for(int i = 0; i < strlen(str); i++){  
        if(str[i] == ',')  
            str[i] = ch;  
    }  
      
     
    printf("%s", str);  
          
    return 0;  
}  

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

#define int ll

main()
{
  while(1){
    int M,T,P,R; cin >> M >> T >> P >> R;
    if(M == 0) break;
    vvi problem(T,vi(P)); // どのチームがどの問題に何回不正解か
    vector<pair<pii,int>> team(T); // 正答数、所要時間合計、チーム番号
    rep(i,T) team[i].snd = i + 1; // 本当はi+1
    rep(i,R){
      int m,t,p,j; cin >> m >> t >> p >> j; t--; p--;
      if(j) problem[t][p]++;
      else{
	team[t].fst.fst++;
	team[t].fst.snd -= m + 20 * problem[t][p];
      }
    }
    sort(rall(team));
    cout << team[0].snd;
    rep(i,T-1){
      if(team[i].fst.fst == team[i+1].fst.fst and team[i].fst.snd == team[i+1].fst.snd) cout << "=";
      else cout << ",";
      cout << team[i+1].snd;
    }
    cout << endl;
    //dump(team);
  }	    
}



Measured memory_bytes: 3124
#include<stdio.h>
   #define NUMBER 10000
   int main(void){
       int i,c=0,x[NUMBER];
       for(i=0;1;i++){
          scanf("%d",&x[i]);
          if(x[i]==0)
            break;
          c++;
     }
      for(i=0;i<c;i++){
         printf("Case %d: %d\n",i+1,x[i]);
      }
      return 0;
  }


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

constexpr ll MOD = 998244353;

namespace math { namespace integer {

ll mod_pow(ll x, ll n, ll mod) { if(n == 0) { return 1; } if(n % 2 == 0) { return mod_pow(x * x % mod, n / 2, mod); } else { return x * mod_pow(x, n - 1, mod) % mod; } }
template<class T> T extgcd(T a, T b, T& x, T& y) { T d = a; if(b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x;} else { x = 1, y = 0; } return d; }
template<class T> T mod_inverse(T x, T mod) { return mod_pow(x, T(mod - 2), mod); /* use fermat */ }
template<class T> T mod_inverse_composite_num_mod(T a, ll mod) { T x, y; extgcd(a, mod, x, y); return (mod + x % mod) % mod; }

}}
using namespace math::integer;

namespace math {

constexpr int MaxFact = 200020;

template<class T = ll>
struct FactRevFactList {
  array<T, MaxFact+1> fact_;
  array<T, MaxFact+1> rev_fact_;

  FactRevFactList() {
    fact_[0] = 1;
    for(int i=1; i<MaxFact; i++) {
      fact_[i] = fact_[i-1] * i;
      fact_[i] %= MOD;
    }

    rev_fact_[MaxFact-1] = mod_pow(fact_[MaxFact-1], (T)MOD-2, MOD);

    for(int i=MaxFact-2; i>=0; i--) {
      rev_fact_[i] = rev_fact_[i+1] * (i+1);
      rev_fact_[i] %= MOD;
    }
  }

  T fact(int x) const { return fact_[x]; }
  T fact_inv(int x) const { return rev_fact_[x]; }
};

template<class T = ll>
struct CombinationBig {
  math::FactRevFactList<> fr_;
  T comb(T n, T r) { return (fr_.fact(n) * fr_.fact_inv(r) % MOD) * fr_.fact_inv(n-r) % MOD; }
};

}

math::CombinationBig<> cbig;

int main() {
  ll N, M, K; cin >> N >> M >> K;
  ll ans = 0;
  rep(k, K + 1) {
    auto c = cbig.comb(N - 1, k) % MOD;
    c *= mod_pow(M - 1, N - k - 1, MOD) % MOD;
    ans += c % MOD;
    ans %= MOD;
  }
  ans *= M;
  ans %= MOD;
  cout << ans << endl;
}


Measured memory_bytes: 6716
//mondai niha saigo ni kaigyou wo ireru toha kaiteimasendesitaga
//saigo ni kaigyou wo irenai to presentation error ni narimasu.
//kiwotukemasyou(^^)

#include <stdio.h>
int main(void){
  
  int n,i;
  scanf("%d",&n);
  int a[n];
  for (i = 0; i < n; i++)
    {
      scanf("%d",&a[i]);
    }
  
  for(i = n-1;i>-1;i--)
    {
      printf("%d",a[i]);
      if(i!=0)printf(" ");

    }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;  
  string A = "abcdefghijklmnopqrstuvwxyz";

  int b[26] ={0};
  for(int i = 0; i<S.size(); i++){
    for(int j = 0; j<26; j++){
      if(S[i] == A[j]){
        b[j]++;
      }
    }
  }
  for(int j = 0; j<26; j++){
    if(b[j] %2 != 0){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

#define N 5100

vector<int> x[N];

int n,m,a,b,c,cnt;
int V[N];

int main(){
	for(int i=0;i<N;i++){
		for(int j=0;j<i+5;j++){
			x[i].push_back(0);
			V[i]=j;
		}
	}
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>a>>b>>c;c++;
		x[a][b]++;
		x[a+c][b]--;
		x[a+c+1][b+1]++;
		x[a][b+1]--;
		x[a+c][b+c+1]++;
		x[a+c+1][b+c+1]--;
	}
	for(int i=0;i<N;i++){
		for(int j=1;j<N;j++){
			if(j<V[i]){
				x[i][j]+=x[i][j-1];
			}
		}
	}
	for(int j=0;j<N;j++){
		for(int i=1;i<N;i++){
			if(j<V[i]){
				x[i][j]+=x[i-1][j];
			}
		}
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n-i;j++){
			if(j+1<V[i+j+1]){
				x[i+j+1][j+1]+=x[i+j][j];
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(j<V[i]){
				if(x[i][j]>=1){cnt++;}
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 65232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int ,int> ii;
typedef vector<ii> vii;
typedef pair<int, vector<int>> pv;
typedef pair<int, string> pis;
#define range(x, n) for(int x = 1; x <= n; x++)
#define deb(x) cout << #x << " " << x << endl;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, c=0;
    string s;
    cin >> n >> s;
    for(int i=0;i<n-2;i++) {
      if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') c++;
    }
    cout << c;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int ar[100001];

int main() {
    int n;
    long long int k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        ar[a] += b;
    }
    for (int i = 1; i <= 100001; ++i) {
        if (k <= ar[i]) {
            cout << i << endl;
            break;
        }
        k -= ar[i];
    }

   return 0;
}


Measured memory_bytes: 1024
<?php 
  fscanf(STDIN,"%d %d %d %d",$a,$b,$c,$d);
  while(1){
    $c -= $b;
    if($c<=0){
      echo "Yes\n";
      exit;
    }
    $a -= $d;
    if($a<=0){
      echo "No\n";
      exit;
    }
  }

Measured memory_bytes: 16136
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define pb push_back
#define ld long double
#define mod 1000000007
#define mk make_pair
#define ull unsigned long long
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main()
{
    ll a,b;
    cin>>a>>b;
    ll ans;
    ans=max((ll)0,a-2*b);
    cout<<ans<<'\n';
    return 0;
}

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

int main(){
  long long int a[1000];
  for(int i=0;i<1000;i++) a[i]=BIG;
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  for(int i=1;i<=n;i++){
    cout<<"node "<<i<<": key = "<<a[i]<<", ";
    if(i==1){
      if(n>1) cout<<"left key = "<<a[i+1]<<", ";
      if(n>2) cout<<"right key = "<<a[i+2]<<", ";
    }
    else{
      cout<<"parent key = "<<a[i/2]<<", ";
      if(a[2*i]!=BIG) cout<<"left key = "<<a[i*2]<<", ";
      if(a[2*i+1]!=BIG) cout<<"right key = "<<a[i*2+1]<<", ";
    }
    cout<<endl;
  }
  return 0;
}
    



Measured memory_bytes: 3068
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)

points_alice = 0
points_bob = 0
for i in range(0, N, 2):
    points_alice += A[i]

for i in range(1, N, 2):
    points_bob += A[i]

print(points_alice - points_bob)

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

string s;
int K;

string mul(string str, int n){
    string res;
    rep(i,n){
        res += str;
        if((int)res.size() > K) break;
    }
    return res.substr(0,K+1);
}

// T := c..c | Nc | N(T) | TT
string read(int &i){
    if((int)s.size() == i || s[i] == ')') return "";

    string str;
    // c..c
    if(isalpha(s[i])){
        while(isalpha(s[i])){
            str += s[i];
            i++;
        }
    }else{
        int num = 0;
        while(isdigit(s[i])){
            num = num*10+(s[i]-'0');
            i++;
        }

        // Nc
        if(isalpha(s[i])){
            str = string(num,s[i]);
            i++;
        }
        // N(T)
        else{
            i++;
            str = mul(read(i),num);
            i++;        
        }
    }
    // TT
    return mul(str+read(i),1);
}


int main(void){
    while(cin>>s>>K, !(s=="0" && K==0)){
        int i = 0;
        string res = read(i);
        if((int)res.size() <= K){
            cout<<0<<endl;
        }else{
            cout<<res[K]<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 8796
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	ll n;
	cin>>n;
	ll t;
	for(t=1;;t++)if(n<=t*(t+1)/2)break;
	ll w=t-t*(t+1)/2+n;
	string s=string(w,')')+"("+string(t-w,')')+string(t-1,'(');
	cout<<s<<endl;
}



Measured memory_bytes: 3352
def comp(T,P):
    if T == P:
        return True
    else:
        return False

def main():
    T = input()
    P = input()
    n1,n2 = len(T),len(P)

    for i in range(n1-n2+1):
        if comp(T[i:i+n2],P):
            print(i)

if __name__ == "__main__":
    main()



Measured memory_bytes: 5576
#include <bits/stdc++.h>
#define LL long long
#define FASTER ios_base::sync_with_stdio(false); cin.tie(0);
using namespace std;

int main()
{
    FASTER;

    int a, b, c;
    cin >> a >> b >> c;
    cout << min(a*b, c) << "\n";
    return 0;
}


Measured memory_bytes: 256
N, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

for i in range(1, len(A)+1):
    #print(i)
    #print(A[:i])
    #print(sum(A[:i]))
    if x < sum(A[:i]):
        #print('a')
        print(i-1)
        break
    elif x == sum(A[:i]):
        #print('b')
        print(i)
        break
    else:
        if i == len(A):
            print(i-1)



Measured memory_bytes: 3060
#include <stdio.h>

int main(){

  int s1,s2,sum,max,maxten,i;
  char ten;
  while(1){
    sum=0;
    max=0;
    for(i=1;i<6;i++){
      scanf("%d%d",&s1,&s2);
      sum=s1+s2;
      if(sum>max){
	max=sum;
	maxten=i;
      }
    }
    if(s1==0 && s2==0)break;
    if(maxten==1)ten='A';
    if(maxten==2)ten='B';
    if(maxten==3)ten='C';
    if(maxten==4)ten='D';
    if(maxten==5)ten='E';
    printf("%c %d\n",ten,max);
  }
  return 0;
}

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

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

  int n = s.size();
  stack<char> st;
  rep(i, n) {
    if (st.empty() || s[i] == 'S') {
      st.push(s[i]);
    } else if (s[i] == 'T' && st.top() == 'T') {
      st.push(s[i]);
    } else if (s[i] == 'T' && st.top() == 'S') {
      st.pop();
    }
  }

  cout << st.size() << endl;
  return 0;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=a;i<=n;++i)
#define lpd(i,a,n) for(int i=a;i>=n;--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int n;

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

    if(sz(a) == 26){
        string b;
        lpd(i,25,0) b += char(i + 'a');
        if(a == b) cout <<-1;
        else{
            lpd(i,sz(a)-1,0){
                lp(inc,1,'z'-a[i]){
                    bool ok = true;
                    lp(j,0,i-1) ok &= a[j] != a[i] + inc;
                    if(ok){
                        lp(j,0,i-1) cout <<a[j];
                        cout <<char(a[i] + inc);
                        return 0;
                    }
                }
            }
        }
    }
    else{
        lp(j,0,25){
            bool ok = true;
            for(char c : a) ok &= c != char(j + 'a');
            if(ok) return cout <<(a + char(j + 'a')), 0;
        }
        assert(false);
    }
}

/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);

abcdefghijklmnopqrstuvwzyx
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
#define dec(i,j,k) for(re int i=j;i>=k;i--)
using namespace std;
const int N=1e6+5;
int n,sum[N],ans,minn,maxx,cur,pos,suf[N],now;
char s[N];
void get(int x){
	now=minn=maxx=0;
	inc(i,1,n){
		if(s[i]=='1') sum[i]=sum[i-1]+1;
		if(s[i]=='0') sum[i]=sum[i-1]-1;
		if(s[i]=='?'){
			if(suf[i]+now+2<=x) sum[i]=sum[i-1]+1,now+=2;
			else sum[i]=sum[i-1]-1;
		} 
		minn=min(minn,sum[i]);
		maxx=max(maxx,sum[i]);
	}
	ans=min(ans,maxx-minn);
}
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	minn=maxx=0;
	inc(i,1,n){
		if(s[i]=='1') sum[i]=sum[i-1]+1;
		else sum[i]=sum[i-1]-1;
		maxx=max(maxx,sum[i]);
	}
	suf[n+1]=-n;
	dec(i,n,1) suf[i]=max(suf[i+1],sum[i]);
	int z=maxx;ans=n; 
	get(z),get(z+1);
	printf("%d",ans);
}

Measured memory_bytes: 12592
#include<stdio.h>
#include<algorithm>
using namespace std;
int h[100010],nex[200010],to[200010],M,n;
void add(int a,int b){
	M++;
	to[M]=b;
	nex[M]=h[a];
	h[a]=M;
}
int d[100010],q[100010];
bool del[100010];
char s[100010];
void topsort(){
	int head,tail,x,i;
	head=1;
	tail=0;
	for(i=1;i<=n;i++){
		if(s[i]=='B'&&d[i]==1)q[++tail]=i;
	}
	while(head<=tail){
		x=q[head++];
		del[x]=1;
		for(i=h[x];i;i=nex[i]){
			if(d[to[i]])d[to[i]]--;
			if(s[to[i]]=='B'&&d[to[i]]==1&&!del[to[i]])q[++tail]=to[i];
		}
	}
}
int f[100010],sum,mn;
int tp(int x){return(d[x]&1)^(s[x]=='W');}
int val(int x){return tp(x)==1?-2:0;}
void dfs(int fa,int x){
	sum+=(tp(x)==1)+2;
	f[x]=val(x);
	for(int i=h[x];i;i=nex[i]){
		if(to[i]!=fa&&!del[to[i]]){
			dfs(x,to[i]);
			mn=min(mn,f[x]+f[to[i]]);
			f[x]=min(f[x],f[to[i]]+val(x));
		}
	}
}
int main(){
	int i,x,y;
	scanf("%d",&n);
	for(i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
		d[x]++;
		d[y]++;
	}
	scanf("%s",s+1);
	topsort();
	for(x=1;x<=n;x++){
		if(!del[x])break;
	}
	if(x>n)
		putchar('0');
	else{
		dfs(0,x);
		sum-=2;
		printf("%d",sum+mn);
	}
}

Measured memory_bytes: 7168
N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
C = zip(A,B)
C = sorted(C)
A, B = zip(*C)
index = 0
count = 0
sum = 0
for i in range(N):
      if(count<=M):
        index = i
        sum += A[i]*B[i]
        count += B[i]
sum +=A[index]*(M-count)
print(sum)

Measured memory_bytes: 26924
#!/usr/bin/python3
from collections import deque

s = input()
head = 1 #1:forward, -1: reverse

q = int(input())
sl = [ s[i] for i in range(len(s)) ]
sq = deque(sl)


for i in range(q):
    ql = input()
    if ql[0] == '1':
        head *= -1
    elif ql[0] == '2':
        (op, f, c) = ql.split()
        ht = 1
        if f == '1':
            ht = head
        else:
            #f == '2':
            ht = head * -1

        if ht == 1:
            sq.appendleft(c)
        else:
            sq.append(c)


if head == 1:
    print(''.join(sq))
else:
    print(''.join(reversed(sq)))


Measured memory_bytes: 9332
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
char S[200000][12];
 
int comp(const void* a, const void* b){
    return strcmp(a, b);
}
 
int main(void){
    int N;
    int i;
    scanf("%d", &N);
    for(i=0;i<N;i++){
        scanf("%11s", S[i]);
    }
 
    qsort(S, N, sizeof(*S), comp);
 
    int ans = 1;
    for(i=1;i<N;i++){
        if(strcmp(S[i-1], S[i]) != 0){
            ans++;
        }
    }
    printf("%d", ans);
 
    return 0;
}

Measured memory_bytes: 6264
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back

typedef long long ll;

int main() {
  ll N, b = 1;
  string ans;

  cin >> N;
  if (N == 0) {
    cout << "0" << endl;
    return 0;
  }
  while (N != 0) {
    if (N % (2*b)) {
      N -= b;
      ans.pb('1');
    } else {
      ans.pb('0');
    }
    b *= -2;
  }

  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        var divide = new String[]{"dream","dreamer","erase","eraser"}; 
        // 入力
        String input = Console.ReadLine();
        String inputR = new String(input.Reverse().ToArray());
        var divideR = new String[4];
        for(int i = 0;i < 4 ;i++){
            divideR[i] = new String(divide[i].Reverse().ToArray());
        }
        Boolean can = true;
        for(int i = 0;i<input.Length;){
            //4つの文字列のいずれかで一致するか
            Boolean can2 = false;
            for(int j = 0; j < 4 ;j++){
                String d = divideR[j];
                if ((i+ d.Length) <= inputR.Length){
                    if (inputR.Substring(i, d.Length) == d){
                        can2 = true;
                        i += d.Length;
                    }
                }
            }
            if (!can2){
                can = false;
                break;
            }
        }
        // 結果出力
        if (can){
            Console.WriteLine("YES");
        }
        else{
            Console.WriteLine("NO");
        }

    }
}


Measured memory_bytes: 20488
n, a, b, c, d = map(int, input().split())
s = input()
if "##" in s[a:max(c,d)]:
	print ("No")
	exit()

if c > d:
	if "..." not in s[max(0,b-2):min(d+1,n)]:
		print ("No")
		exit()
print ("Yes")

Measured memory_bytes: 3572
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE long long
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
double dmax(double a,double b){
    return a>b?a:b;
}

int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}

int ruizyou(int a, int b){
    int i, num=1;
    rep(i, b){
        num = num*a;
    }
    return num;
}

int main(void){
    int i, n = in();
    int a[3];
    rep(i,3){
        a[i] = (n%ruizyou(10, 3-i))/(ruizyou(10, 2-i));
        if(a[i]==9) printf("1");
        else printf("9");
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 128