akhauriyash/Code-Regression huggingface dataset:
//cwystc <--> 陈威宇是天才  --by cwy
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const double PI=acos(-1);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for (int i=(a);i<=(b);i++)
#define per(i,a,b) for (int i=(a);i>=(b);i--)
#define Rep(i,a,b) for (int i=(a);i<(b);i++)
#define Per(i,a,b) for (int i=(a);i>(b);i--)
#define travel_set(it,a) for (set<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define travel_map(it,a) for (map<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define travel_vec(it,a) for (vector<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define p(x) cout << x << endl;
#define def cout << "find" << endl;
#define what_is(x) cout << #x << " is " << x << endl;
template <class T>T sqr(T x){return x*x;}
template <class T>T alex(T x){return (x>0)?x:-x;}
template <class T>void read(T&x){
	x=0;T f=1;char ch=getchar();
	while ((ch<48||ch>57)&&ch!=45)ch=getchar();
	if (ch==45)f=-1,ch=getchar();
	while (ch>=48&&ch<=57)x=x*10+ch-48,ch=getchar();
	x*=f;
}

//-------------------------------------------------head-------------------------------------------------

#define maxn 30
char s[maxn];
int c[maxn];char ans;
bool check(){
	Rep(i,0,26)if (c[i]==0){ans=i+'a';return true;}return false;
}
int main(){
	scanf("%s",s);int l=strlen(s);
	Rep(i,0,l)c[s[i]-'a']++;
	if (check()){printf("%s",s);putchar(ans);puts("");return 0;}
	else{
		int lst=l-1;while (true){
			c[s[lst]-'a']--;s[lst]++;while (s[lst]>'z'){lst--;if (lst<0){puts("-1");return 0;}c[s[lst]-'a']--;s[lst]++;}
			c[s[lst]-'a']++;if (c[s[lst]-'a']==1){rep(i,0,lst)putchar(s[i]);puts("");return 0;}
		}
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int W,H;
	int i,j;
	
	while(W!=0 || H!=0){
		scanf("%d%d",&H,&W);
		if(W==0 && H==0) break;
		for(i=0; i<H; i++){
			for(j=0; j<W; j++){if ((i+j)%2==0) printf("#"); else printf(".");}
			printf("\n");
		}
		printf("\n");
	}
return 0;
}

Measured memory_bytes: 572
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	int N, D; cin >> N >> D;
	
	vector<vector<int>> v(N);
	for(int i = 0; i < N; i++){
		vector<int> vec(D);
		for(int j = 0; j < D; j++){
			cin >> vec[j];
		}
		v[i] = vec;
	}

	int ans = 0;
	for(int i = 0; i < N - 1; i++){
		for(int j = i + 1; j < N; j++){
			double sum = 0;
			
			for(int k = 0; k < D; k++){
				sum += pow(abs(v[i][k] - v[j][k]), 2.0);
			}

			double root = sqrt(sum);
			if(floor(root) == root) ans++;
		}
	}

	cout << ans;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> v;
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (i + j != n / 2 * 2 + 1) {
        v.push_back({i, j});
      }
    }
  }
  cout << v.size() << endl;
  for (auto e : v) {
    cout << e.first << " " << e.second << endl;
  }
}


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


def read():
    N, M, X = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    return N, M, X, A


def solve(N, M, X, A):
    l, r = 0, 0
    for a in A:
        if a < X:
            l += 1
        elif a > X:
            r += 1
    return min(l, r)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N),P,M;
    vector<Pll> v;
    priority_queue<ll> que;
    rep(i,N){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    ll b = A[0];
    for(int i=1;i<N-1;i++){
        if(A[i] >= 0){
            v.push_back(Pll(b,A[i]));
            b -= A[i];
        }else{
            v.push_back(Pll(A[N-1],A[i]));
            A[N-1] -= A[i];
        }
    }
    v.push_back(Pll(A[N-1],b));
    A[N-1] -= b;
    cout << A[N-1] << endl;
    rep(i,N-1){
        cout << v[i].first <<" "<<v[i].second << endl;
    }
    /*
    if(N==2){
        cout << A[1]-A[0] << endl;
        cout << A[1] << " " << A[0] <<endl;
        return 0;
    }

    if(!(A[0] < 0 && 0 <= A[N-1])){
        if(A[0] >= 0){
            A[0] -= A[N-1];
            A.erase(A.begin()+N-1);
        }else{
            A[N-1] = A[0] - A[N-1];
            A.erase(A.begin()+0);
        }
    }
    rep(i,A.size()){
        if(A[i] >= 0){
            P.push_back(A[i]);
        }else{
            M.push_back(A[i]);
        }
    }
    ll ans = A[N-1];
    rep(i,A.size()-1){
        if(P.size() >= M.size()){
            v.push_back(Pll(A[i], ans));
            ans += A[i];
        }else{
            v.push_back(Pll(ans,A[i]));
            ans -= A[i];
        }
    }

    cout << ans << endl;
    rep(i,v.size()){
        cout << v[i].first << " " << v[i].second << endl;
    }*/
}


Measured memory_bytes: 4336
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int n; scanf("%d", &n);
	int x[1000], y[1000];
	for(int i = 0; i < n; i++) scanf("%d %d", &x[i], &y[i]);
	int p = (abs(x[0]) + abs(y[0])) % 2;
	for(int i = 1; i < n; i++){
		if((abs(x[i]) + abs(y[i])) % 2 != p){ puts("-1"); return 0; }
	}
	int m = 31 + (p ? 0 : 1);
	printf("%d\n", m);
	for(int i = 0; i < m; i++) printf("%d%c", i == 31 ? 1 : 1 << i, i + 1 == m ? '\n' : ' ');
	char c[2][2] = {'L', 'D', 'U', 'R'};
	if(!p) for(int i = 0; i < n; i++) x[i]--;
	for(int i = 0; i < n; i++){
		int u = x[i] + y[i], v = x[i] - y[i];
		for(int j = 0; j < 31; j++) putchar(c[((u - 1) / 2 + (1 << 30)) >> j & 1][((v - 1) / 2 + (1 << 30)) >> j & 1]);
		if(!p) putchar('R');
		puts("");
	}
	return 0;
}

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

int main() {

	int n, k, q;
	scanf("%d %d %d", &n, &k, &q);
	vector<int> a(q);
	vector<int> par(n);
	for(int i = 0; i < n; i++) {
		par[i] = k - q;
	}
	for(int i = 0; i < q; i++) {
		scanf("%d", &a[i]);
		par[a[i] - 1] += 1;
	}
	for(int i = 0; i < n; i++) {
		if(par[i] > 0) {
			printf("%s\n", "Yes");
		}else {
			printf("%s\n", "No");
		}
	}
}

Measured memory_bytes: 1408
#include<iostream>
using namespace std;
long long dp[55][55*55];
int main(){
  int a,n;
  cin>>n>>a;
  dp[0][0]=1;
  for(int i=1;i<=n;i++){
    int x;
    cin>>x;
    for(int j=i-1;j>=0;j--){
      for(int k=0;k<=55*j;k++){
        dp[j+1][k+x]+=dp[j][k];
      }
    }
  }
  long long ans=0;
  for(int i=1;i<=n;i++) ans+=dp[i][i*a];
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 1024
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
//  cout.precision(15); cout << fixed;

int main() {
  int n, a, b; cin >> n >> a >> b;
  int total = 0;
  loop(i,1,n+1) {
    string s = to_string(i);
    int sum = 0;
    for (auto c: s) sum += c-'0';
    if (a <= sum and sum <= b) total += i;
  }
  cout << total << endl;
  return 0;
}


Measured memory_bytes: 3740
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}

int ketakazu(int n){ //何桁かを返す
	return int(log10(double(n)))+1;
}
int ketanani(int n,int a){ //nの下から桁目かを返す
	return (n/int(pow(10,double(a-1))))%10;
}
int ketasum(int n){ //各桁の和を返す
	int k=int(log10(double(n)))+1;
	int sum=0;
	FOR(i,1,k+1){
		sum+=(n/int(pow(10,double(i-1))))%10;
	}
	return sum;
}

int main(){
	string s;
	cin>>s;
	if(s.size()==1){
		cout<<s[0]<<endl;
		return 0;
	}
	int m=0;
	rep(i,s.size()-1){
		int x=0;
		rep(j,s.size()-i-1){
			x+=s[j]-48;
		}
		m= max( m, (i+1)*9+x-1);
	}
	int y=0;
	rep(i,s.size()){
		y+=s[i]-48;
	}
	m=max(m,y);
	cout<<m<<endl;
}





Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(m)]
    ab.sort(key=lambda a: a[1])
    res = 0
    cur = 0
    for i in range(m):
        if cur <= ab[i][0]:
            res += 1
            cur = ab[i][1]
    print(res)

if __name__ == '__main__':
    main()

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

inline int rd() {
  int x = 0;
  bool f = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + (c ^ 48);
    c = getchar();
  }
  return f ? -x : x;
}

int main() {
  int n = rd();
  ll ans = 0;
  int lst = 0, nw;
  for (int i = 1; i <= n; ++i) {
    nw = rd();
    if (nw > lst) lst = nw;
    else ans += lst - nw;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 3768
#include <cstdio>

using namespace std;

using ll = long long;
const int N = 2e5+5;
ll cnt[N];
int arr[N];

int main() {
    // freopen("D.in", "r", stdin);
    ll total = 0;
    int n; scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int t; scanf("%d", &t);
        arr[i] = t;
        cnt[t]++;
    }
    for (int i = 0; i <= n; i++) {
        total += cnt[i] * (cnt[i] - 1) / 2;
    }

    for (int i = 0; i < n; i++) {
        ll v = cnt[arr[i]];
        printf("%lld\n", total - v * (v-1) / 2 + (v-1)*(v-2)/2);
    }
    return 0;
}

Measured memory_bytes: 3840
#include <stdio.h>

int main (void) {
	int n=0, i;
	int debt = 100000;
	scanf("%d", &n);
	
	for(i=0; i<n; i++) {
		debt *= 1.05;
		if( debt % 1000 != 0)
			debt = debt - (debt%1000) + 1000;
	}
		
	printf("%d\n", debt);

	return 0;
}

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

class Graph
{
private:
	map<int, list<int>>adjList;
public:

	Graph(int v)
	{
		for (int i = 1; i <= v; i++)
		{
			list<int>l;
			adjList[i] = l;
		}
	}

	void addEdge(int u, int v)
	{
		adjList[u].push_back(v);
	}

	// void Print()
	// {
	// 	for (auto i : adjList)
	// 	{
	// 		cout << i.first << " -> ";
	// 		for (auto j : i.second)
	// 		{
	// 			cout << j << " ";
	// 		}
	// 		cout << endl;
	// 	}
	// }

	int path_value(int src, vector<int>&dp)
	{
		if (dp[src] != -1)
		{
			return dp[src];
		}

		//ab path calculate karna padega
		int ans = 0;
		for (auto nbr : adjList[src])
		{
			ans = max(ans, 1 + path_value(nbr, dp));
		}
		return dp[src] = ans;
	}

	int Longest_path(int n)
	{
		vector<int>dp(n + 1, -1);
		int ans = INT_MIN;
		for (auto vertex : adjList)
		{
			int node = vertex.first;
			int curr = path_value(node, dp);
			ans = max(ans, curr);
			//dp[vertex] = ans;
		}
		// for (auto i : dp)
		// {
		// 	cout << i << " ";
		// }
		// cout << endl;
		return ans;
	}
};
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, m;
	cin >> n >> m;
	Graph g(n);
	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		g.addEdge(u, v);
	}
	//g.Print();
	cout << g.Longest_path(n);
	return 0;
}

Measured memory_bytes: 18652
#include<iostream>
#include<numeric>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long li;
#define chmin(a,b) (a>(b)?a=(b),1:0)
#define abs(n) max((n),-(n))
#define dist(a,b) max((a)-(b),(b)-(a))
#define chmax(a,b) (a<(b)?a=(b),1:0)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 1000000000
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  // ここでストリームに obj を書き込みます。
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}


int main(){
  li x,y ; cin >>x >>y;
  int cnt=0;
  while(y>=x){
    cnt++;
    y/=2;
  }
  print(cnt);
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define se second
#define fi first
#define pb push_back
#define cn cout<<"\n"
#define rep(i,a,b) for(int i = a; i < b; i++)
#define repr(i,a,b) for(int i = a; i >= b; i--)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

#define _ ios::sync_with_stdio(0); cin.tie(0);

#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define ll long long
#define vll vector<ll>

const int INF = 1e9 + 1;

using namespace std;


int n;
vi w, v;

ll memo[102][100002];

ll dp(int i, int ww) {
	
	if(i == n) return 0;
	if(memo[i][ww] != -1) return memo[i][ww];

	ll ans = -1;
	if(ww - w[i] >= 0) ans = dp(i + 1, ww - w[i]) + v[i];

	ans = max(ans, dp(i + 1, ww));

	return memo[i][ww] = ans;
}


int main(){
	_

	int W;

	cin>>n>>W;

	w.assign(n, 0), v.assign(n, 0);

	rep(i, 0, n)
		cin>>w[i]>>v[i];

	rep(i, 0, n + 1)
		rep(j, 0, W + 1)
			memo[i][j] = -1;

	cout<<dp(0, W)<<"\n";

	return 0;
}

Measured memory_bytes: 79232
/*
ID: amagica1
TASK: ariprog
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
#define INF INT_MAX
#define NINF -INF
#define mp make_pair
#define endl '\n'
#define boost() cin.tie(0); cin.sync_with_stdio(0)
#define For(i, a, b) for(int i=a; i<b; i++)
#define FOR(i, a, b) for(int i=a; i<=b; i++)
#define Rev(i, a, b) for(int i=a; i>b; i--)
#define REV(i, a, b) for(int i=a; i>=b; i--)
#define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;
typedef long double ld;
typedef int64_t l;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
const ll MOD = 1e9 + 7;
const int MAXN = 100005;
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
mt19937 rng;
int N, M;
int main() {
    //-----------FILE------------//
    //freopen("airprog.in", "r", stdin);
    //freopen("airprog.out", "w", stdout);
    //----------------------------//
    cin >> N >> M;
    cout << (N == M? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
p $<.to_a.drop(1).map{|x|
	Complex(*x.split.map(&:to_i))
}.product([*0...5000]).select{|x|
	(x[0]/Complex.polar(1,2*Math::PI*x[1]/5000)).arg.abs<=Math::PI/2
}.group_by{|x|x[1]}.map{|x|
	x[1].map{|y|y[0]}.inject(:+).abs
}.max


Measured memory_bytes: 55676
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String s = scan.nextLine();
		StringBuilder show = new StringBuilder();
		int countB = 0;
		for (int i=0;i<s.length();i++) {
			if(s.charAt(i)=='B') {
				if(show.length()>0) {
				show.deleteCharAt(show.length()-1);
				}
			}else {
		show.append(s.charAt(i));
		}
	}
		System.out.println(show);

	}
}



Measured memory_bytes: 21716
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

constexpr cat mod = 1000000007;

void solve(int R, int par, vector< vector<int> > & G, vector<int> & S, vector<cat> & cnt_valid, vector<cat> & cnt_all, vector< vector<cat> > & cnt) {
	int N = S.size();
	S[R] = 1;
	cnt[R][0] = 1;
	ALL_THE(G[R], it) if(par != *it) {
		solve(*it, R, G, S, cnt_valid, cnt_all, cnt);
		if(S[*it]%2 == 0) cnt[*it][S[*it]] = (cnt[*it][S[*it]] - cnt[*it][0] * cnt_valid[*it]) % mod;
		vector<cat> cnt_nw(N+1, 0);
		for(int i = 0; i <= S[*it]; i += 2) if(cnt[*it][i] != 0) for(int j = 0; j <= S[R]; j += 2)
			cnt_nw[i+j] = (cnt_nw[i+j] + cnt[R][j] * cnt[*it][i]) % mod;
		cnt[R] = cnt_nw;
		S[R] += S[*it];
	}
	cnt_valid[R] = 0;
	if(S[R]%2 != 0) return;
	for(int i = 0; i < S[R]; i += 2)
		cnt_valid[R] = (cnt_valid[R] + cnt[R][i] * cnt_all[S[R]-i]) % mod;
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector< vector<int> > G(N);
	for(int i = 0; i < N-1; i++) {
		int x, y;
		cin >> x >> y;
		G[--x].push_back(--y);
		G[y].push_back(x);
	}
	vector<cat> cnt_valid(N), cnt_all(N+1, 0);
	cnt_all[0] = 1;
	for(int i = 2; i <= N; i++) cnt_all[i] = cnt_all[i-2] * (i-1) % mod;
	vector< vector<cat> > cnt(N, vector<cat>(N+1, 0));
	vector<int> S(N);
	solve(0, 0, G, S, cnt_valid, cnt_all, cnt);
	if(cnt_valid[0] < 0) cnt_valid[0] += mod;
	cout << cnt_valid[0] << "\n";
	return 0;
}

// look at my code
// my code is amazing


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

int main(){
    int N;  cin >> N;
    vector<int> b(N+1,0);
    for(int i=1; i<=N; i++) cin >> b[i];

    vector<int> ans;
    while(b.size()!=1){
        int n = b.size()-1;
        bool flag = false;
        // for(int i=1; i<=n; i++){
        //     cout << b[i] << " ";
        // }cout << "--> ";

        for(int i=n; i>=1; i--){
            if(b[i]==i){
                // cout << i << " " << b[i] << endl;
                ans.push_back(i);
                b.erase(b.begin()+i);
                flag = true;
                break;
            }
        }

        if(!flag){
            cout << -1 << endl;
            return 0;
        }
    }

    for(int i=N-1; i>=0; i--){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define ll long long
ll a,b,c,k,sum;
int main()
{
    cin>>a>>b>>c>>k;
    if (a>=k) sum+=k,k=0;
    else sum+=a,k=k-a;
    if (k)
    {
        if (b>=k) k=0;
        else k=k-b;
        if (k) sum-=k;
    }
    cout<<sum;
}


Measured memory_bytes: 3636
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let r: i32 = input();
    println!("{}", 3 * r * r);
}


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

int main(){
  int h,n,s=0;
  cin>>h>>n;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    s+=x;
  }
  if(s>=h) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define INF 1000000000

typedef long double Real;
#define EPS 1e-13
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

int x[4001];

int main(){
  REP(i,2001)x[i] = min(i+1,2001-i);
  int n;
  while(~scanf("%d",&n)){
    ll sum = 0;
    REP(i,n+1){
      sum += x[i]*x[n-i];
    }
    cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;

int main()
{
    string s;
    cin >> s;
    int k;
    cin >> k;
    //priority_queue<string, vector<string>, greater<string> > que;
    //priority_queue<string> que;
    set<string> se;
    int l = s.size();
    rep(i,l){
        for(int j=1;j+i<=l && j<=5;j++){
            se.insert(s.substr(i,j));
        }
    }
    auto minitr = se.begin(); 
    rep(i,k-1){
        minitr++;
    }
    cout << *minitr;
    //cout << que.top();
}

Measured memory_bytes: 1664
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
/*
for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;

}
*/
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, E, F, K,L, W, H, P, Q, R, X, Y;
  //ll a[N+1];	
  cin >> N >> K;
  vector<ll> l;
  rep(i, N){
    cin>> A;
    l.push_back(A);
  }
  sort(ALL(l));
  ll ans = 0;
  rep(i, K){
    ans += l[N-1-i];
  }
  cout << ans << endl;
  
}



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

bool solve() {
    ll X;
    cin >> X;
    if ( X >= 30 ) return true;
    return false;
}

int main() {
    string ans = solve() ? "Yes" : "No";
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(ll i=0;i<n;++i)
#define FOR(i,j,n) for(ll i=j;i<n;++i)
#define MOD (1e9 + 7)

int main(void){
    ll N;
    cin >> N;
    ll A[N];
    ll res = 0;
    map <ll,ll> dp;
    REP(i,N){
        cin >> A[i];
        dp[i-A[i]] += 1;
    }
    REP(i,N){
        res += dp[A[i]+i];
    }
    cout << res << endl;

}

Measured memory_bytes: 27792
#include <cstdio>

int main()
{
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    
    if((a+b)>(c+d))
    {
        printf("Left");
    }
    else if((a+b)==(c+d))
    {
        printf("Balanced");
    }
    else
    {
        printf("Right");
    }
    
}

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

int main() {
    int digits[3];
    //Read 3 digits into digits[0], [1] and [2]
    scanf("%d%d%d", digits, digits + 1, digits + 2);

    //Sort digits in ascending order
    sort(digits, digits + 3);

    //Compute answer
    int ans = 10 * digits[2] + digits[0] + digits[1];
    printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 256
//
// tested with : g++ (GCC) 8.3.0
//

#include <iostream>
#include <string>
using namespace std;

int main() {
    int N;//N種類
    cin >> N;
    int X;//全部でXグラム
    cin >> X;
    int* m = new int[N];//M[N]各ドーナツのグラム
    for (int i = 0; i < N; i++)
        cin >> m[i];

    int count = 0;//ドーナツの数
    int championdnum = 0;//チャンピオンドーナツ番号
    int championdg = 1001;//チャンピオンドーナツグラム

    //N種類のドーナツを作る。
    for (int i = 0; i < N; i++) {
        X -= m[i];
        count++;
        if ( m[i] < championdg ){
            championdg = m[i];
            championdnum = i;//チャンピオン検出。
        }
    }

    //チャンピオンドーナツを作れるだけ作る。
    while (m[championdnum] <= X) {
        X -= m[championdnum];
        count++;
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;

int main() {
	char a, b, c;
	string s;
	int sum = 700;

	cin >> s;

	if (s[0] == 'o')
		sum += 100;
	if (s[1] == 'o')
		sum += 100;
	if (s[2] == 'o')
		sum += 100;

	cout << sum;

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  char a, b, c, d ,e, f;
  cin >> a >> b >> c >> d >> e >> f;
  //cout << a << b << c << d << e << f;
  if ((a == f) and (b == e) and (c == d)) {
     cout << "YES";
  }
  else {
    cout << "NO";
  }
}


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

typedef long long int ll;

int main()
{
    ll n, ans = 0, cnt = 0;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0;i < n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());

    for(ll i = 0;i < n - 1;i++){
        if(a[i] == a[i + 1]){
            cnt++;
        }
        else{
            cnt++;
            if(a[i] == cnt){

            }
            else if(a[i] < cnt){
                ans += cnt - a[i];
            }
            else{
                ans += cnt;
            }
            cnt = 0;
        }
    }

    cnt++;
    if(a[n - 1] == cnt){

    }
    else if(a[n - 1] < cnt){
        ans += cnt - a[n - 1];
    }
    else{
        ans += cnt;
    }

    cout << ans;

    return 0;
}

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

#include <iostream>
#define pb push_back
#define sort_incr(v) sort(v.begin(),v.end());
#define sort_decr(v) {sort(v.begin(),v.end()); reverse(v.begin(),v.end());}
#define take_input(v,n) for(ll i=0,temp;i<n;i++){cin>>temp;v.pb(temp);}
#define fastio {ios_base::sync_with_stdio(false);    cin.tie(NULL);}
#define ALL(v) v.begin(),v.end()

typedef long long ll;
using namespace std; 



////*********           REMOVE DUPLICATES FROM VECTOR       **********///////


vector<int>  remove_duplicate_elements(vector<int> v)
{
    vector<int>::iterator ip;
    ip = unique(v.begin(), v.end()); 
    v.resize(std::distance(v.begin(), ip)); 
    return v;
}


//// **************                CONVERT STRING TO UNIQUE CHARACTERS              **************////                  
string make_unique_string(string s)
{
    string s1="";
    for(int i=0;i<s.length();i++)
    {
        bool flag=true;
        for(int j=0;j<s1.length();j++)
        {
            if(s1[j]==s[i])
            {flag=false;break;}
        }
        
        if(flag)
        s1=s1+s[i];
        
    }
    return s1;
}

//////// Three Element Vector 
struct vec_thre
{
    int first ,second,third;
};


/////// Comparing on sorting a vector


bool comp(vec_thre a , vec_thre b)
{
    if (a.first != b.first ) 
        return a.first < b.first; 
    if (a.second != b.second) 
            return a.second < b.second; 
}

/////////Sorting vector on the basis of second Element of vector 

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 


// Driver function to sort the vector elements by  first element of pair in descending order, 
//if first is same than second is consdidered 
bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
    
        if(a.first!=b.first)
       return (a.first > b.first);
       
       return (a.second>b.second);

} 


int main() 
{
int n,k;
cin>>n>>k;
vector<int> v;
take_input(v,n);
sort(ALL(v));
ll su=0;
for(int i=0;i<k;i++)
{
    su=su+v[i];
}
cout<<su;
    
    return 0; 
} 























Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

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

  typedef pair<int, int> P;
  vector<P> A_ind(N);

  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
    A_ind[i] = P(A[i], i);
  }

  vector<vector<int>> dp(N + 1, vector<int>(N + 1));
  sort(all(A_ind), greater<P>());
  rep(l, N) {
    rep(r, N) {
      int i = l + r;
      if (i >= N)
        continue;
      int a = A_ind[i].fi;
      int pind = A_ind[i].se;

      chmax(dp[l + 1][r], dp[l][r] + a * abs(pind - l));
      chmax(dp[l][r + 1], dp[l][r] + a * abs(pind - (N - 1 - r)));
    }
  }

  int ans = 0;
  rep(i, N) {
    chmax(ans, dp[i][N - i]);
  }
  cout << ans << endl;
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

 int main(){
int a, b;
cin >> a >> b;
string S;
cin >> S;
if(S.at(a) != '-') {
no;
return 0;
}

REP(i, S.size()){
if(i != a && S.at(i) == '-'){
  no;
  return 0;
}   
}


yes;
 }

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main
{
	final int inf=(int)(1e9+1),dx[]={0,0,-1,1},dy[]={-1,1,0,0};
	int n,m,k,dist[][],min;
	boolean locked[][];
	Point start;
	private void solve()throws IOException
	{
		n=nextInt();
		m=nextInt();
		k=nextInt();
		locked=new boolean[n+1][m+1];
		start=null;
		for(int i=1;i<=n;i++)
		{
			String s=nextLine();
			for(int j=1;j<=m;j++)
			{
				if(s.charAt(j-1)=='S')
					start=new Point(i,j);
				locked[i][j]=s.charAt(j-1)=='#';
			}
		}
		//initialise the core cells
		dist=new int[n+1][m+1];
		for(int i=1;i<=n;i++)
			Arrays.fill(dist[i],inf);
		bfs1();
		//update the rest of the cells
		min=inf;
		bfs2();
		out.println((min+k-1)/k+1);
	}
	void bfs1()
	{
		Queue<Point> queue=new LinkedList<>();
		queue.add(start);
		dist[start.x][start.y]=0;
		while(!queue.isEmpty())
		{
			Point p=queue.remove();
			for(int i=0;i<4;i++)
			{
				int x=p.x+dx[i];
				int y=p.y+dy[i];
				if(x>=1 && x<=n && y>=1 && y<=m && dist[x][y]>dist[p.x][p.y]+1 && !locked[x][y])
				{
					dist[x][y]=dist[p.x][p.y]+1;
					if(x==1 || x==n || y==1 || y==m)
					{
						System.out.println(1);
						System.exit(0);
					}
					if(dist[x][y]<k)
						queue.add(new Point(x,y));
				}
			}
		}
	}
	void bfs2()
	{
		Queue<Point> queue=new LinkedList<>();
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				if(dist[i][j]!=inf)
				{
					dist[i][j]=0;
					queue.add(new Point(i,j));
				}
		while(!queue.isEmpty())
		{
			Point p=queue.remove();
			for(int i=0;i<4;i++)
			{
				int x=p.x+dx[i];
				int y=p.y+dy[i];
				if(x>=1 && x<=n && y>=1 && y<=m && dist[x][y]>dist[p.x][p.y]+1)
				{
					dist[x][y]=dist[p.x][p.y]+1;
					if(x==1 || x==n || y==1 || y==m)
						min=Math.min(min,dist[x][y]);
					queue.add(new Point(x,y));
				}
			}
		}
	}
	class Point
	{
		int x,y;
		Point(int a,int b)
		{
			x=a;
			y=b;
		}
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 46456
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll inf = 1e5;
ll w[105], v[105];
ll dp[3005][3005];
ll a[200005];
int main(){
	string s;
	string t;
	cin >> s;
	cin >> t;
	for (int i = 0; i <= s.size(); i++) {
		dp[0][i] = 0;
	}
	for (int j = 0; j <= t.size(); j++) {
		dp[j][0] = 0;
	}

	for (int i = 0; i < t.size(); i++) {
		for (int j = 0; j < s.size(); j++) {
			if (s[j] == t[i]) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
			}
			else {
				dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
			}
		}
	}
	string ans = "";
	int x = s.size();
	int y = t.size();
	while (x > 0 && y > 0) {
		if (dp[y][x] == dp[y - 1][x]) {
			y--;
		}
		else if (dp[y][x] == dp[y][x - 1]) {
			x--;
		}
		else {
			x--;
			y--;
			ans.push_back(s[x]);
		}

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

Measured memory_bytes: 70784
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i)  
#else
  #define DUMP(i)  
#endif

#define GETTYPE(i) 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;

const int EPS = 1e-9;

int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  while(cin >> s){
    bool ans = s[0] == '9' || s[1] == '9';
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

struct state {
    int D;
    vector<int> c;
    vector<vector<int>> s;
    vector<int> before;

    state(int D,vector<int> &c,vector<vector<int>> &s): D(D),c(c),s(s),before(26,-1) {}

    vector<int> optimization() {
        vector<ll> ans(D + 1,0);
        vector<int> indexs(D + 1);
        int i;
        for (i = 0;i < D - 3;i+=2) {
            vector<int> idxs = next_four_day(i);
            for (int j = 1;j <= 3;++j) {
                before[idxs[j]] = i + j;
                indexs[i + j] = idxs[j] + 1;
            }
        }
        while (i < D) {
            int idx = next_day(i);
            before[idx] = i;
            indexs[i + 1] = idx + 1;
            i += 1;
        }
        return indexs;
    }

    int next_day(int d) {
        int idx = -1,ans = -INF;
        rep(i,26) {
            int ret = s[d][i];
            int x = before[i];
            before[i] = d;
            rep(j,26) {
                ret -= (d - before[j]) * c[j];
            }
            if (ans < ret) {
                ans = ret;
                idx = i;
            }
            before[i] = x;
        }
        return idx;
    }

    vector<int> dfs(int i,int k,int bf,int now) {
        vector<int> rets(1);
        rets[0] = -INF;
        int idx = -1;

        //start
        if (k < 0) {
            rep(j,26) {
                int x = before[j];
                before[j] = i;
                vector<int> ne = dfs(i + 1,j,bf,now);
                if (rets[0] < ne[0]) {
                    idx = j;
                    swap(rets,ne);
                }
                before[j] = x;
            }
            rets.push_back(idx);
            return rets;
        }
        
        //score
        bf += s[i][k];
        rep(j,26) {
            bf -= (i - before[j]) * c[j];
        }

        //finish
        if (now == i) {
            vector<int> rets(1);
            rets[0] = bf;
            return rets;
        }
        
        //nextday
        rep(j,26) { 
            int x = before[j];
            before[j] = i;
            vector<int> ne = dfs(i + 1,j,bf,now);
            if (rets[0] < ne[0]) {
                swap(rets,ne);
                idx = j;
            }
            before[j] = x;
        }
        rets.push_back(idx);
        return rets;
    }

    vector<int> next_four_day(int d) {
        vector<int>  ans = dfs(d,-1,0,d + 3);
        return ans;
    }

};

int main() {
    int D; cin >> D;;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(26));
    rep(i,D)rep(j,26) cin >> s[i][j];
    
    state st(D,c,s);
    vector<int> ans = st.optimization();
    rep(i,D) printf("%d\n",ans[i + 1]);
    return 0;
}

Measured memory_bytes: 3816
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)

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

def dfs(m):
    for i in range(len(adj[m])):
        if depth[adj[m][i]] == float('inf'):
            depth[adj[m][i]] = depth[m] + 1
            point[adj[m][i]] += point[m]
            dfs(adj[m][i])


point = [0]*(n+1)
depth = [float('inf')]*(n+1)
adj = [[]for _ in range(n+1)]

for i in range(n-1):
    adj[ab[i][0]].append(ab[i][1])
    adj[ab[i][1]].append(ab[i][0])

for i in range(q):
    point[px[i][0]] += px[i][1]

depth[1] = 1
dfs(1)

for i in range(1,n+1):
    print(point[i],end = ' ')










'''
n,q = map(int,input().split())
ab = [list(map(int,input().split()))for i in range(n-1)]
px = [list(map(int,input().split()))for i in range(q)]

def dfs(m):
    if m in vdic:
        for i in range(len(vdic[m])):
            point[vdic[m][i]] += point[m]
            dfs(vdic[m][i])

point = [0]*(n+1)

vdic = {}
for i in range(n-1):
    if ab[i][0] not in vdic:
        vdic[ab[i][0]] = []
    vdic[ab[i][0]].append(ab[i][1])

for i in range(q):
    point[px[i][0]] += px[i][1]

dfs(1)

for i in range(1,len(point)):
    print(point[i],end = ' ')

'''

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

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map
#define mtv(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)

vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out( 
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cout << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    stringstream ss; ss << H;
    cout << args[idx] << "- " << ss.str() << ", ";
    debug_out(args, idx + 1, LINE_NUM, T...);
}


ll dx[5] = {0,0,-1,1};
ll dy[5] = {-1,1,0,0};

void doit(){
    ll n,m,i,j;
    cin >> n >> m;
    ll sr,sc,dr,dc;
    cin >> sr >> sc >> dr >> dc;
    sr--;sc--;dc--;dr--;
    char ch;
    vector< vector<bool> >v(n+2 , vector<bool>(m+2));
    rep(i,0,n){
        rep(j,0,m){
            cin >> ch;
            v[i][j] = (ch == '.');
        }
    }
    priority_queue< pair<ll,pii>, vector<pair<ll,pii>>, greater<pair<ll,pii>>>pq;
    vector< vector<ll> >vis(n+2 , vector<ll>(m+2,LLONG_MAX));
    pq.push({0LL,{sr,sc}});
    while(!pq.empty()){
        auto cur = pq.top();
        // mtv(cur.ss.ff,cur.ss.ss,cur.ff);
        if(cur.ss.ff == dr and cur.ss.ss == dc){
            cout << cur.ff;
            return;
        }
        pq.pop();
        vis[cur.ss.ff][cur.ss.ss] = cur.ff;
        rep(i,0,4){
            ll nr = cur.ss.ff + dx[i], nc = cur.ss.ss+dy[i];
            if(nr < 0 or nc < 0 or nr == n or nc == m or !v[nr][nc])continue;
            if(vis[nr][nc] > cur.ff){
                pq.push({cur.ff,{nr,nc}});
                vis[nr][nc] = cur.ff;
            }
        }
        rep(i,-2,3){
            rep(j,-2,3){
                ll nr = cur.ss.ff + i, nc = cur.ss.ss + j;
                if(nr < 0 or nc < 0 or nr == n or nc == m or !v[nr][nc])continue;
                if(vis[nr][nc] > cur.ff + 1){
                    pq.push({cur.ff+1,{nr,nc}});
                    vis[nr][nc] = cur.ff+1;
                }
            }
        }
    }
    cout << -1 << nl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
   //  cin >> t;
    for(ll i = 1; i <= t; i++){
       // cout << "Case #"<< i << ": ";
        doit();
    }
}


Measured memory_bytes: 11844
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,d;
    cin>>n>>d;
    double x[n][d];
    rep(i,n){
        rep(j,d){
            cin>>x[i][j];
        }
    }
    int cnt=0;
    rep(i,n){
        repi(k,i+1,n){
            double sum=0;
            rep(j,d){
                double diff=abs(x[i][j]-x[k][j]);
                sum+=diff*diff;
            }
            rep(j,sum+1) if(j*j==sum) cnt++;
        }
    }
    cout<<cnt;
}

Measured memory_bytes: 3752
#include <stdio.h>
#define BLACK 0
#define WHITE 1
#define GRAY -1


int a[101][101];
int f[101];
int n;
int color[101];
int time=0;
int d[101];
int k;

void DFS (void);
void DFSVisit(int);

int main(void){
    int t,u,i,j;

    //printf("point 1\n");
    
    
    scanf("%d",&n);
    
    //printf("point 2\n");
    
    for(i=1;j<=n;i++){
        for(j=1;j<=n;j++){
            a[i][j]=0;
        }
    }
    
    for(i=1;i<=n;i++){
       // printf("point 3\n");
        scanf("%d",&u);
       // printf("point 4\n");
        scanf("%d",&k);
       // printf("point 5\n");
            for(j=1;j<=k;j++){
              //  printf("point 6\n");
                scanf("%d",&t);
            // printf("%d %d\n",i,j);
            a[i][t] =1;
        }
    }
    

    
    
    
    
    
    
    
    
    
    
    DFS();
    for(i=1;i<=n;i++){
        printf("%d %d %d\n",i,d[i],f[i]);
    }
    return 0;
}

void DFS(void){
    //int time;
    int u;
    
    for(u=1;u<=n;u++){
        color[u]=WHITE;
        time=0;
    }
    
    for(u=1;u<=n;u++){
        if(color[u]==WHITE)DFSVisit(u);
    }
    
}


void DFSVisit(int u){
    int v;
    
    color[u]=GRAY;
    d[u] = ++time;
    
    for(v=1;v<=n;v++){
        if((color[v]==WHITE) && (a[u][v]==1)){
           DFSVisit(v);
        }
    }
    color[u] = BLACK;
    f[u]=++time;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST freopen("in.txt","r",stdin);
#define ab(a) ((a < 0) ? (-(a)) : (a))
#define all(a) a.begin(), a.end()
#define ones(a) __builtin_popcount(a)

const int N = (int)1e5 + 9;
bool dp[N];

int main(){
  fastIO;
  memset(dp, false, sizeof dp);
  string s;
  cin >> s;
  int j = 1;
  dp[0] = true;
  for(int i = 0;i < s.size(); i ++ ){
    if(i >= 4){
      if(s.substr(i - 4, 5) == "dream"){
        if(dp[j-5] == true){
          dp[j] = true;
        }
      }
    }
    if(i >= 6){
      if(s.substr(i - 6, 7) == "dreamer"){
        if(dp[j-7] == true){
          dp[j] = true;
        }
      }
    }
    if(i >= 4){
      if(s.substr(i - 4, 5) == "erase"){
        if(dp[j-5] == true){
          dp[j] = true;
        }
      }
    }
    if(i >= 5){
      if(s.substr(i - 5, 6) == "eraser"){
        if(dp[j-6] == true){
          dp[j] = true;
        }
      }
    }
    j ++ ;
  }
  if(dp[(int)s.size()] == true)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}


Measured memory_bytes: 640