akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int main()
{
	int n;
	int a, b;
	scanf("%d", &n);
	
	for (a = 1 ; a <= 9 ; a++)
	{
		if (n % a != 0)
			continue;
		b = n / a;
		
		if ((1 <= b) && (b <= 9))
		{
			printf("Yes\n");
			return 0;
		}
	}
		
	printf("No\n");
	return 0;
}


Measured memory_bytes: 128
/// Date: 07-April-2018
/// MD:NUR ALAM
#include "bits/stdc++.h"
using namespace std;
int main(){

     int a,b,c,x=0,y=0;
     cin>>a>>b>>c;
     x=c*2;
     y=abs(a-b)+1;
     if(y<x){
         for(int i=a;i<=b;i++){
            cout<<i<<endl;
         }
     }
         else {
            for(int i=a;i<=(a+c)-1;i++)
                 cout<<i<<endl;
                for(int j=(b-c)+1;j<=b;j++){
                    cout<<j<<endl;

                }
            }
         }



Measured memory_bytes: 256
// https://atcoder.jp/contests/abc179/submissions/16938175
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  ll N, X, M;
  cin >> N >> X >> M;
  ll total = 0;
  ll x = X;
  vector<int> indices(M, -1);
  vector<int> a;
  int l = 0;
  while (indices[x] == -1) {
    indices[x] = l;
    total += x;
    a.push_back(x);
    x = (x * x) % M;
    l++;
  }
  int cycle = l - indices[x];
  ll cycleSum = 0;
  for (int i = indices[x]; i < l; i++) {
    cycleSum += a[i];
  }
  ll ans = 0;
  if (N <= l) {
    for (int i = 0; i < N; i++) {
      ans += a[i];
    }
  } else {
    ans += total;
    N -= l;
    ans += cycleSum * (N / cycle);
    N %= cycle;
    for (int i = 0; i < N; i++) {
      ans += a[indices[x] + i];
    }
  }
  cout << ans << endl;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

#define P pair<lli,lli>

struct edge{
	lli to,cost;
};
lli dist[100100];


vector<vector<edge>> g;

void func(lli now,lli from){
	for(auto e:g[now]){
		if(e.to==from)continue;
		dist[e.to] = dist[now]+e.cost;
		func(e.to,now);
	}
}


signed main(){

	lli n;
	cin>>n;
	g.resize(n);

	REP(i,0,n-1){
		lli u,v,w;
		cin>>u>>v>>w;
		u--,v--;
		g[u].push_back({v,w});
		g[v].push_back({u,w});
	}

	dist[0]=0;
	func(0,-1);

	REP(i,0,n)cout<<dist[i]%2<<endl;

	return 0;
}

Measured memory_bytes: 10112
# frozen_string_literal: true

n = gets.to_i
s = Array.new(n) { gets.to_i }.sort
sum = s.inject(:+)

if sum % 10 == 0
  tmp = s.detect { |i| i % 10 != 0 }
  puts tmp ? sum - tmp : 0
else
  puts sum
end

Measured memory_bytes: 1788
w,h,n = map(int, input().split())
min_x, max_x, min_y, max_y = 0, w, 0, h
for _ in range(n):
  x,y,a = map(int, input().split())
  if a==1:
    min_x = max(min_x, x)
  elif a==2:
    max_x = min(max_x, x)
  elif a==3:
    min_y = max(min_y, y)
  else:
    max_y = min(max_y, y)
print((max_x-min_x if max_x>=min_x else 0)*(max_y-min_y if max_y>=min_y else 0))
    

Measured memory_bytes: 3060
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <deque>
#include <map>
using namespace std;

#define ii pair <int, int>
#define lli long long
#define pb push_back
#define X first
#define Y second

const int Mod = 1E9 + 7;
const int Inf = 1E9 + 7;
const int N = 30 + 10;

int n, a[N];
ii x[N][N];

void Input()
{
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        for (int j = 1; j <= a[i]; j++) cin >> x[i][j].X >> x[i][j].Y;
    }
}

void Solve()
{

    int res = 0;
    for (int i = 1; i < (1 << n); i++) {
        bool ok = true;
        int cnt = 0;
        for (int j = 1; j <= n; j++) if (i & (1 << j - 1)) {
            cnt++;
            for (int k = 1; k <= a[j]; k++) {
                int Next = x[j][k].X;
                bool ck = (i & (1 << Next - 1));
                if (ck != x[j][k].Y) ok = false;
               // if (i == 3) cout << j << " " << Next << " " << ck << " " << x[j][k].Y << endl;
            }
        }
        if (ok) res = max(res, cnt);
    }
    cout << res;
}

#define task "test"
int main()
{
    if (fopen(task ".inp", "r")) {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    int testcase = 1;
    /// cin >> testcase;
    while (testcase--) {
        Input();
        Solve();
    }
}




Measured memory_bytes: 3164
#include<cstdio>
int pow(int a){
	int k=1;
	for(int i=1;i<=a;i++){
		k=k*10;
	}
	return k;
}
int main(){
	int n;
	scanf("%d",&n);
	int a=n;
	int b=0;
	for(int i=8;i>=0;i--){
		b=b+a/pow(i);
		a=a%pow(i);
	}
	if(n%b==0)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int n, a[109];
int main() {
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) {
		for(int j = i - 1; j >= 0; j--) {
			if(a[j] > a[j + 1]) swap(a[j], a[j + 1]);
			else break;
		}
		for(int j = 0; j < n; j++) {
			if(j) cout << ' ';
			cout << a[j];
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 3084
n = gets.to_i
date = []
n.times do
  x1,y1,x2,y2,x3,y3,x4,y4 = gets.chomp.split.map(&:to_r)

  # if (y2 - y1)/(x2 - x1) == (y4 - y3)/(x4 - x3)
  if (y2 - y1) * (x4 - x3) == (y4 - y3) * (x2 - x1)
    date << "YES"
  else
    date <<  "NO"
  end
end

n.times do |ni|
  puts date[ni]
end



Measured memory_bytes: 6912
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x) memset(x , 0 , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;

int dp[xx][3];
int Data[xx][3];

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

  int N;
  cin >> N;

  for(int i = 0; i < N; i++){
    cin >> Data[i][0] >>  Data[i][1] >> Data[i][2]; 
  }

  dp[0][0] = Data[0][0];
  dp[0][1] = Data[0][1];
  dp[0][2] = Data[0][2];

  for(int i = 1; i < N; i++) {
     
     for(int j = 0; j < 3; j++){
       for(int k = 0; k < 3; k++){
         if(j == k) continue;
         dp[i][j] = max(dp[i][j] , dp[i-1][k] + Data[i][j]);
       }
     }
  }

  int ans = max({dp[N-1][0] , dp[N-1][1] , dp[N-1][2]});
  cout << ans << '\n';

}

Measured memory_bytes: 8380
#include<stdio.h>

int main(){
  char c[1200];
  int a=0;
  scanf("%[^\n]%*c",c);

  while(c[a]!='\0'){
    
    if(65<=c[a]&&c[a]<=90){
      c[a]=c[a]+32;
    }else if(97<=c[a]&&c[a]<=122){
      c[a]=c[a]-32;
    }

    a++;
  }
  printf("%s\n",c);
  return 0;
}



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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int dp[201010] = {0};
char bdp[201010] = {0};
int bbdp[201010] = {0};

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

  string s;
  cin >> s;
  int n = s.size();
  vector<int> pos(26, n + 1);
  dp[n] = 1;
  dp[n + 1] = 0;
  bdp[n] = 'a';
  bbdp[n] = n + 1;
  for (int i = n - 1; i >= 0; i--) {
    pos[s[i] - 'a'] = i + 1;
    char small;
    int next = n, index;
    for (int j = 0; j < 26; j++) {
      if (dp[pos[j]] < next) {
        next = dp[pos[j]];
        small = 'a' + j;
        index = pos[j];
      }
    }
    dp[i] = next + 1;
    bdp[i] = small;
    bbdp[i] = index;
  }
  int i = 0;
  while (i <= n) {
    cout << bdp[i];
    i = bbdp[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 2324
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D, E;
  cin >> A >> B >> C >> D >> E;
  int a=(10-A%10)%10;
  int b=(10-B%10)%10;
  int c=(10-C%10)%10;
  int d=(10-D%10)%10;
  int e=(10-E%10)%10;
  int suma=A+B+C+D+E+b+c+d+e;
  int sumb=A+B+C+D+E+a+c+d+e;
  int sumc=A+B+C+D+E+a+b+d+e;
  int sumd=A+B+C+D+E+a+b+c+e;
  int sume=A+B+C+D+E+a+b+c+d;
  int SUM=suma;
  if (SUM>sumb) SUM=sumb;
  if (SUM>sumc) SUM=sumc;
  if (SUM>sumd) SUM=sumd;
  if (SUM>sume) SUM=sume;
  cout << SUM << endl;
}
  

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var imp = Console.ReadLine().Split(' ');
            int A = int.Parse(imp[0]);
            int B = int.Parse(imp[1]);
            int C = int.Parse(imp[2]);
            if ((B - A) == (C - B))
            {
                Console.Write("YES");
            }
            else
            {
                Console.Write("NO");
            }
        }
    }
}


Measured memory_bytes: 13140
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <vector>
#include <list>
 
using namespace std;
typedef long long ll;
 
#define mod 1000000007
#define INF 1000000000
#define SIZE 1000
int n,c[SIZE],w[SIZE];
bool memo[SIZE][SIZE];

void dfs(int l,int r,int now,int weight){
  if(l < 0 || n <= r) return;
  if(memo[l][r]) return;
  
  if(c[now] < weight) return;

  memo[l][r] = true;

  //cerr << "(" << l << "," << r << ")" << endl;
  
  weight += w[now];
  
  dfs(l,r+1,r+1,weight);
  dfs(l-1,r,l-1,weight);

}
  

int main(){
  int l[SIZE],r[SIZE];
  int dp[SIZE+10];
  
  scanf("%d",&n);

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

  for(int i=0;i<n;i++){
    dfs(i,i,i,0);
  }
  
  for(int i=0;i<=n;i++){
    dp[i] = INF;
  }

  dp[0] = 0;

  for(int i=0;i<n;i++){

    for(int j=i;j<n;j++){
      if(memo[i][j]) dp[j+1] = min(dp[j+1],dp[i]+1);
    }

  }

  cout << dp[n] << endl;
  
  return 0;
}

Measured memory_bytes: 4144
#include<stdio.h>
int main(){
   int a,b,c;
   scanf("%d %d %d",&a,&b,&c);
   if(a<b){
     if(b>c){
        if(a<c){
           printf("%d %d %d\n",a,c,b);
        }else{
           printf("%d %d %d\n",c,a,b);
        }
     }else{
        printf("%d %d %d\n",a,b,c);
     }
   }else{
       if(a>c){
          if(b<c){
           printf("%d %d %d\n",b,c,a);
          }else{
           printf("%d %d %d\n",c,b,a);
          }
       }else{
           printf("%d %d %d\n",b,a,c);
       }
   }
   return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
    {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
    {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
    {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
    #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
    #define dump(...)
    #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

int cnt(int x) {
    return to_string(x).size();
}
signed main() {
    int n; cin >> n;
    int ans = 0;
    REPI (x, 1, n + 1) {
        ans += cnt(x) % 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
/*
  AOJ 1277
  Title:Minimal Backgammon
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
#include <float.h>
#define ONE_SIXTH (1.0/6.0)

int N,T,L,B;
int sq[100];
double memo[101][101];

int myabs(int x)
{
  return (x>=0)?x:(-x);
}

double solve(int rest,int turn)
{
  int i,next_pos;
  double ret;

  if(memo[rest][turn]!=DBL_MAX)
    ret=memo[rest][turn];
  else if(rest==0)
    ret=1.0;
  else if(turn<=0)
    ret=0.0;
  else if(turn==1 && rest<=6)
    ret=ONE_SIXTH;
  else
    for(i=1,ret=0.0;i<=6;i++)
      {
	next_pos=myabs(rest-i);
	if(sq[N-next_pos]==0)
	  ret += ONE_SIXTH * solve(next_pos,turn-1);
	else if(sq[N-next_pos]=='L')
	  ret += ONE_SIXTH * solve(next_pos,turn-2);
	else if(sq[N-next_pos]=='B')
	  ret += ONE_SIXTH * solve(N,turn-1);
      }
  //printf("%d %d :%lf\n",rest,turn,ret);
  memo[rest][turn]=ret;
  return(ret);
}
main()
{
  int i,j,l,b;
  double ret;
  while(scanf("%d %d %d %d",&N,&T,&L,&B)  && (N||T||L||B))
    {

      memset(sq,0,sizeof(sq));
      for(i=0;i<=100;i++)
	{
	  for(j=0;j<=100;j++)
	    memo[i][j]=DBL_MAX;
	}

      for(i=0;i<L;i++)
	{
	  scanf("%d",&l);
	  sq[l]='L';
	}
      for(i=0;i<B;i++)
	{
	  scanf("%d",&l);
	  sq[l]='B';
	}
      ret=solve(N,T);
      printf("%lf\n",ret);
    }
  return(0);
}

Measured memory_bytes: 720
import sys
N,M = map(int,input().split())
A,B = [],[]
for i in range(N):
    A.append(input())
for i in range(M):
    B.append(input())

for i in range(N-M+1):
    for j in range(N-M+1):
        ans = True
        for ii in range(M):
            for jj in range(M):
                if A[i+ii][j+jj] != B[ii][jj]: 
                    ans = False
        if ans:
            print("Yes")
            sys.exit()

print("No")

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

long long dp[100005];
long long a[100005];

int main()
{
    long long n , k;

    cin >> n >> k;


    for(long long i = 1 ; i<=n ; i++)
    {
        cin >> a[i];
        dp[i] = 1000000000;
    }

    dp[1] = 0;

    for(long long i = 1 ; i<=n ; i++)
    {
        for(int j = i+1 ; j<=(i+k) && j<=n ; j++)
        {
            dp[j] = min(dp[j] , dp[i] + abs(a[j] - a[i]));
        }
    }

    cout <<  dp[n];

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
	int a[2], k;
	cin >> a[0] >> a[1] >> k;

	for(auto i = 0; i < k; ++i) {
		if(a[i % 2] % 2 == 1) {
			a[i % 2] -= 1;
		}
		a[i % 2] /= 2;
		a[(i + 1) % 2] += a[i % 2];
	}

	cout << a[0] << ' ' << a[1] << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

#define MAX 1000
signed main() {
	pii a[MAX] = {};
	for (int p, q; cin >> p >> q;) {
		memset(a, 0, sizeof(a));
		string ans = "";
		int l, r;
		rep(i, 0, MAX) {
			p *= 10;
			bool flag = false;
			rep(j, 0, i) { if (a[j] == pii(p / q, p%q)) { l = j; r = i; flag = true; break; } }
			if (flag)break;
			a[i] = pii(p / q, p%q);
			ans += to_string(p / q);
			p %= q;
			if (p == 0)break;
		}
		cout << ans << endl;
		if (p != 0) {
			rep(i, 0, l)cout << " ";
			rep(i, l, r)cout << "^";
			cout << endl;
		}
	}
	return 0;
}

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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
        #define eprintf(...) 42
#endif

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

int n, m;
vector<int> g[100000], G[100000];
bool used[100000];
vector<int> sorted;
int num[100000];

void dfs(int x)
{
  if(used[x]) return;
  used[x] = true;

  for(auto to : g[x]){
    dfs(to);
  }

  sorted.pb(x);
}

void toposort()
{
  rep(i, n){
    dfs(i);
  }

  reverse(all(sorted));
}

int main()
{
  cin >> n >> m;
  rep(i, n+m-1){
    int a, b;
    cin >> a >> b;
    g[--a].pb(--b);
    G[b].pb(a);
  }

  toposort();

  rep(i, n){
    num[sorted[i]] = i;
  }

  int root = sorted[0];
  reverse(all(sorted));

  vector<int> ans(n);
  for(int i : sorted){
    int t = root;
    for(int j : G[i]){
      if(num[t] < num[j]){
        t = j;
      }
    }
    ans[i] = t+1;
  }
  ans[root] = 0;

  rep(i, n){
    cout << ans[i] << endl;
  }

/*
  rep(i, n){
    cout << num[i] << " ";
  }
  cout << endl;
*/

  return 0;
}


Measured memory_bytes: 16380
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;
 
// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
// 
 
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 
 
#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return 
 
 
#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)
 
#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>
 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
 
#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5+5
#define N (1ll<<10)
#define pi 3.141592653589793238462643

void solve(){
    ll n;
    vl p, q;
    cin>>n;
    loop(i,0,n){
        ll x;
        cin>>x;
        p.pb(x);
    }
    loop(i,0,n){
        ll x;
        cin>>x;
        q.pb(x);
    }
    vl perm;
    loop(i,1,n+1) perm.pb(i);
    ll ans1, ans2;
    ll cnt = 0;
    do{
        cnt++;
        if(perm == p){
            ans1 = cnt;
        }
        if(perm == q){
            ans2 = cnt;
        }
    }while(next_permutation(all(perm)));
    print(abs(ans1-ans2));  
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

 
    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
        
 
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var s = bufio.NewScanner(os.Stdin)

func getInt() int {
	s.Scan()
	a, _ := strconv.Atoi(s.Text())
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func main() {
	s.Split(bufio.ScanWords)
	n := getInt()
	a := make([]int, n)

	for i := range a {
		a[i] = getInt()
	}

	l, r := make([]int, n), make([]int, n+1)
	l[0] = 0
	for i := 1; i < n; i++ {
		l[i] = gcd(l[i-1], a[i-1])
	}

	r[n] = 0
	for i := n - 1; i > 0; i-- {
		r[i] = gcd(r[i+1], a[i])
	}

	m := make([]int, n)
	for i := 0; i < n; i++ {
		m[i] = gcd(l[i], r[i+1])
	}

	sort.Ints(m)
	t := len(m)
	fmt.Println(m[t-1])

}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> x(N), y(N), z(N);
  rep(i, 0, N) cin >> x[i] >> y[i] >> z[i];
  vector<int> ids(N);
  iota(ids.begin(),ids.end(), 0);
  ll ans = 0;
  sort(ids.begin(), ids.end(), [&](int i, int j) { return x[i] + y[i] + z[i] > x[j] + y[j] + z[j];});
  ll tx = 0, ty = 0, tz = 0;
  rep(i, 0, M) tx += x[ids[i]], ty += y[ids[i]], tz += z[ids[i]];
  ans = max(ans, abs(tx) + abs(ty) + abs(tz));

  sort(ids.begin(), ids.end(), [&](int i, int j) { return x[i] + y[i] - z[i] > x[j] + y[j] - z[j];});
  tx = 0, ty = 0, tz = 0;
  rep(i, 0, M) tx += x[ids[i]], ty += y[ids[i]], tz += z[ids[i]];
  ans = max(ans, abs(tx) + abs(ty) + abs(tz));

  sort(ids.begin(), ids.end(), [&](int i, int j) { return x[i] - y[i] + z[i] > x[j] - y[j] + z[j];});
  tx = 0, ty = 0, tz = 0;
  rep(i, 0, M) tx += x[ids[i]], ty += y[ids[i]], tz += z[ids[i]];
  ans = max(ans, abs(tx) + abs(ty) + abs(tz));

  sort(ids.begin(), ids.end(), [&](int i, int j) { return x[i] - y[i] - z[i] > x[j] - y[j] - z[j];});
  tx = 0, ty = 0, tz = 0;
  rep(i, 0, M) tx += x[ids[i]], ty += y[ids[i]], tz += z[ids[i]];
  ans = max(ans, abs(tx) + abs(ty) + abs(tz));

  sort(ids.begin(), ids.end(), [&](int i, int j) { return x[i] + y[i] + z[i] < x[j] + y[j] + z[j];});
  tx = 0, ty = 0, tz = 0;
  rep(i, 0, M) tx += x[ids[i]], ty += y[ids[i]], tz += z[ids[i]];
  ans = max(ans, abs(tx) + abs(ty) + abs(tz));

  sort(ids.begin(), ids.end(), [&](int i, int j) { return x[i] + y[i] - z[i] < x[j] + y[j] - z[j];});
  tx = 0, ty = 0, tz = 0;
  rep(i, 0, M) tx += x[ids[i]], ty += y[ids[i]], tz += z[ids[i]];
  ans = max(ans, abs(tx) + abs(ty) + abs(tz));

  sort(ids.begin(), ids.end(), [&](int i, int j) { return x[i] - y[i] + z[i] < x[j] - y[j] + z[j];});
  tx = 0, ty = 0, tz = 0;
  rep(i, 0, M) tx += x[ids[i]], ty += y[ids[i]], tz += z[ids[i]];
  ans = max(ans, abs(tx) + abs(ty) + abs(tz));

  sort(ids.begin(), ids.end(), [&](int i, int j) { return x[i] - y[i] - z[i] < x[j] - y[j] - z[j];});
  tx = 0, ty = 0, tz = 0;
  rep(i, 0, M) tx += x[ids[i]], ty += y[ids[i]], tz += z[ids[i]];
  ans = max(ans, abs(tx) + abs(ty) + abs(tz));

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


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main(){

	int i;
	char pro[85];

	while(fgets(pro,81,stdin) != NULL){
		while(1){
			if(strstr(pro,"the")!=NULL || strstr(pro,"that")!=NULL || strstr(pro,"this")!=NULL) break;
			for(i=0;pro[i]!='\0';i++){
				if(islower(pro[i]))
					pro[i]=(pro[i]-'a'+1)%26+'a';
			}
		}
		printf("%s",pro);
	}

	return 0;
}

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

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

    int n;
    cin >> n;
    if (n <= 999) {
        cout << "ABC" << endl;
    } else {
        cout << "ABD" << endl;
    }
}


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

const int INF = 200000;

int main() {
	int n; cin >> n;
	vector<int> dp(n + 1, INF);
	dp.at(0) = 0;
	for (int i = 0; i < n; i++) {
		int p = 1;
		while (i + p <= n) {
			dp.at(i + p) = min(dp.at(i + p), dp.at(i) + 1);
			p *= 6;
		}
		p = 1;
		while (i + p <= n) {
			dp.at(i + p) = min(dp.at(i + p), dp.at(i) + 1);
			p *= 9;
		}
	}
	cout << dp.at(n) << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
using namespace std;
const int N = 1000010;
char S[N], T[N];
int pre[N], d[N], q[N], l, r;
int main() {
	int n; scanf("%d",&n);
	scanf("%s",S + 1); scanf("%s",T + 1);
	bool flag = true; rep(i,1,n) if (S[i] != T[i]) flag = false; if (flag) { printf("0\n"); return 0; }
	int mn = n;
	dep(i,n,1) {
		mn = min(mn, i);
		while (mn > 0 && S[mn] != T[i]) mn--;
		if (!mn) { printf("-1\n"); return 0; } 
		pre[i] = mn;
	}
	int ans = 1;
	dep(i,n,1) if (pre[i] > pre[i - 1]) {
		while (l < r && q[l] - (r - l) >= i) l++;
		q[r++] = pre[i];
		if (pre[i] < i) ans = max(ans, r - l + 1); 	
	}
	cout <<ans<<endl;
	return 0;
}

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

const int MAXN = 200055;

ll S[MAXN*2], W[MAXN*2];

int B[MAXN*2];
int A[MAXN];

ll Ans;
int N, L;

ll getSum(int s, int e) {
	if(s > e) return 0;
	return S[s] - S[e+1];
}
ll f(int s, int e) {
	return W[s] - W[e+1] - S[e+1]*(e-s+1)*2;
}
ll g(int s, int e) {
	return getSum(s, e)*(e-s+1)*2 - f(s, e);
}

void goRight(int s, int e) {
	int lc = N-s+1, rc = e-N-1;
	ll t = 0, rt = 0;
	if(lc+1 <= rc) {
		t += g(e-lc-1, e-1) + getSum(N+1, e-lc-2) * (lc*2+1);
		t += f(s, N) + getSum(s, N);
	} else {
		t += g(N+1, e-1);
		t += f(s, s+rc-1) + getSum(s, s+rc-1);
		t += getSum(s+rc, N) * rc*2;
	}
	if(Ans < t) Ans = t;
}

void solve() {
	for(int i = 1; i <= N; i++) {
		B[N+i+1] = A[i];
		B[i] = A[i]-L;
	}
	for(int i = N*2+1; 0 <= i; i--)
		S[i] = S[i+1] + (B[i+1]-B[i]);
	for(int i = N*2+1; i; i--)
		W[i] = W[i+1] + S[i+1]*2 + (B[i+1]-B[i]);

	for(int s = 2, e = N+2; e <= N*2+1; s++, e++)
		goRight(s, e);
}

int main() {
	ios::sync_with_stdio(false);

	cin >> L >> N;
	for(int i = 1; i <= N; i++) cin >> A[i];

	solve();
	reverse(A+1, A+N+1);
	for(int i = 1; i <= N; i++) A[i] = L-A[i];
	solve();

	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647 >> 1); // 10^9 + 5000
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Kunitaka{
    template<
        typename TYPE,
        std::size_t SIZE
    >
    std::size_t array_length(const TYPE (&array)[SIZE])
    {
        return SIZE;
    }
}
using namespace Kunitaka;
namespace Printer{
    void br(){
        cout << endl;
    }

    void loop_cnt(int i){
        cout << "i = " << i << endl;
    }

    void loop_cnt(int i, int j){
        cout << "i = " << i << ", " << "j = " << j << endl;
    }

    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T, class S>
    void print(T x, S y){
        cout << x << "," << y << endl;
    }

    template<class T, class S, class U>
    void print(T x, S y, U z){
        cout << x << "," << y << "," << z << endl;
    }

    template<class T, class S>
    void print(pair<T, S> p){
        cout << p.first << ", " << p.second << endl;
    }

    template<
        typename TYPE,
        std::size_t SIZE
    >
    void print(const TYPE (&array)[SIZE]){
        int lim = array_length(array);
        for(int i=0; i<lim; i++){
            if(i) cout << " ";
            cout << array[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<S> v){
        for(int i=0; i<v.size(); i++){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<vector<S> > vv){
        for(int i=0; i<vv.size(); i++){
            for(int j=0; j<vv[i].size(); j++){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void yesno(bool x){
        if(x) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
};
using namespace Printer;

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//


    // input
    cout << fixed << setprecision(10);
    ll A; cin >> A;

    // variable
    ll ans = 0;
    // solve
    ans = A / 2;
    if(A % 2 == 1) ans++;

    print(ans);
    
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int NArray[N+1];
    for (int i=1; i < N + 1; i++){
        NArray[i] = i;
    }

    int largest = 1;
    bool is_loop = true;
    while (is_loop){
        is_loop = false;
        for (int i=1; i < N + 1; i++){
            if (NArray[i] % 2 == 0){
                NArray[i] /= 2;
                largest = i;
                is_loop = true;
            }
        }
        // cout << largest << endl;
    }
    cout << largest << endl;

}

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

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

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

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 2*(int)1e6+1000;
int n, k, c, lf[maxn], rt[maxn];
char s[maxn];

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

	cin >> n >> k >> c;
	cin >> (s+1);
	int tot = 0;
	ms(lf, 0);
	ms(rt, 0);
	for (int i = 1; i <= n; ++i) {
  		if (s[i] != 'x') {
  			lf[i] = 1;
  			i += c;
  			++tot;
  		}
	}
	if (tot > k) return 0;
	tot = 0;
	for (int i = n; i >= 1; --i) {
  		if (s[i] != 'x') {
  			rt[i] = 1;
  			i -= c;
  			++tot;
  		}
	}
	vi ans;
	for (int i = 1; i <= n; ++i) {
		if (lf[i] && rt[i]) ans.eb(i);
	}
	for (int x : ans) cout << x << '\n';
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 18292
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
#define Mod 1000000007
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }
    }
}
ll ckck(ll N)
{
    ll lo=1,hi=1e10;
    ll  mid,ind;
    ll cnt;
    while(lo<=hi)
    {
        mid=lo+(hi-lo)/2;
        cnt=mid*(mid+1);
        cnt/=2;
        cnt-=1;
        if(N>cnt)
        {
            ind=mid;
            lo=mid+1;
        }
        else
        {
            hi=mid-1;
        }
    }
    return ind;
}

int main()
{
   int A,B,C,D;
   cin>>A>>B>>C>>D;
   int ok;
   int cnt=1;
   while(1)
   {
       if(cnt%2==1)
       {
           C-=B;
           if(C<=0)
           {
               ok=1;
               break;
           }
       }
       else
       {
           A-=D;
           if(A<=0)
           {
               ok=0;
               break;
           }
       }
       cnt++;
   }
   if(ok==1)
    cout<<"Yes";
   else
    cout<<"No";

}


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

int main(){
  string S;
  cin>>S;
  int count=0;
  int max_count=0;
  for (int i=0;i<S.size();i++){
    if (S.at(i)=='T'||S.at(i)=='C'||S.at(i)=='G'||S.at(i)=='A'){
      count++;
    }
    else{
      max_count=max(max_count,count);
      count=0;
    }
    if (i==S.size()-1){
      max_count=max(max_count,count);
    }
  }
  cout<<max_count<<endl;
}

Measured memory_bytes: 256
tg = 0
ls = 1
md = 2
MOD = 10**9+7
n = int(input())
l = n.bit_length()
# ^tight/loose, +tight/loose/middle, bitnum
dp = [[[0] * l for _ in range(3)] for i in range(2)]
for i in range(l):
    if i == 0:
        # 10
        dp[tg][tg][0] = 1
        # 00
        dp[ls][md][0] = 1
        continue
    # i-th bit is 1
    if n & (1 << l - i - 1):
        # 10
        dp[tg][tg][i] += dp[tg][tg][i-1]
        dp[ls][ls][i] += dp[ls][md][i-1]
        dp[ls][tg][i] += dp[ls][tg][i-1]
        dp[ls][ls][i] += dp[ls][ls][i-1]
        # 00
        dp[ls][md][i] += dp[tg][tg][i-1]
        dp[ls][ls][i] += dp[ls][md][i-1]
        dp[ls][md][i] += dp[ls][tg][i-1]
        dp[ls][ls][i] += dp[ls][ls][i-1]
        # 11 
        dp[ls][md][i] += dp[ls][md][i-1]
        dp[ls][ls][i] += dp[ls][ls][i-1]
    # i-th bit is 0
    else:
        # 10
        dp[ls][ls][i] += dp[ls][ls][i-1]
        dp[ls][md][i] += dp[ls][md][i-1]
        # 00
        dp[tg][tg][i] += dp[tg][tg][i-1]
        dp[ls][ls][i] += dp[ls][md][i-1]
        dp[ls][ls][i] += dp[ls][ls][i-1]
        dp[ls][tg][i] += dp[ls][tg][i-1]
        # 11 
        dp[ls][tg][i] += dp[ls][md][i-1]
        dp[ls][ls][i] += dp[ls][ls][i-1]
    for xp in dp:
        for pp in xp:
            pp[i] %= MOD

ans = 0
for xp in dp:
    for pp in xp:
        ans += pp[-1]
        ans %= MOD
print(ans)

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

int main() {
    long long A, B, K;
    cin >> A >> B >> K;
    if (K < A) cout << A - K << " " << B << endl;
    else if (K < A + B) cout << 0 << " " << A + B - K << endl;
    else cout << "0 0" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int n;
    int d,x;
    int a[100000];
    a[0]=0;
    int sum;
    while(cin>>n){
        sum=0;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            sum=sum+abs(a[i]-a[i-1]);
        }
        sum=sum+abs(a[n]);
        a[n+1]=0;
        for(int i=1;i<=n;i++){
            int t=min(a[i-1],a[i+1]);
            int h=max(a[i-1],a[i+1]);
            if(a[i]>=t&&a[i]<=h){
                cout<<sum<<endl;
            }
            else if(a[i]<t){
                    //cout<<2*abs(a[i]-min(a[i],a[i-1]))<<endl;
                cout<<sum-2*abs(a[i]-t)<<endl;
            }
            else{
                cout<<sum-2*abs(a[i]-h)<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#define sum(l, r) (l > 0 ? sums[r - 1] - sums[l - 1] : (r > 0 ? sums[r - 1] : 0))
#define sum2(l, r) (l > 0 ? sums2[r - 1] - sums2[l - 1] : (r > 0 ? sums2[r - 1] : 0))
#define abs(x) (x < 0 ? -x : x)
using namespace std;
int main() {
	long long n, k;
	cin >> n >> k;
	
	vector <long long> ar(n);
	vector <long long> sums(n);	//Pozitivno
	vector <long long> sums2(n);	//sve
	
	long long x = 0;
	long long y = 0;
	
	for(long long i = 0; i < n; i++) {
		cin >> ar[i];
		y += ar[i];
		if(ar[i] > 0) x += ar[i];
		sums[i] = x;
		sums2[i] = y;
	}
	
	long long s;
	
	for(long long i = 0; i < n - k + 1; i++) {
		
		long long sm = sum2(i, i + k);
		
		long long z = sum(0, i) + sum(i + k, n);
		if(sm > 0) z += sm;
		
		if(z > s || i == 0) {
			s = z;
		}
	}
	
	cout << s;
	
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#define pq priority_queue
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;


int main(){
  int n;
  cin>>n;
  ll x[n],y[n];
  for (int i = 0; i < n; i++) {
    cin>>x[i];
    y[i]=x[i];
  }
  sort(y,y+n);
  ll mid=y[n/2];
  ll middash=y[n/2-1];
  for (int i = 0; i < n; i++) {
    if(x[i]<mid) cout<<mid<<endl;
    else cout<<middash<<endl;
  }
  return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define int long long
#define inf 1000000000000000000             /** inf = 10^18 */
using namespace std;


signed main()
{
    int n,tot=1;
    cin>>n;
    int a[n];

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

    for (int i=0; i<n; i++)
    {
        if (a[i]==0)
        {
            cout<<0;
            return 0;
        }
    }
    for (int i=0; i<n; i++)
    {
        if (tot>inf/a[i])
        {
            cout<<-1;
            return 0;
        }
        else
        {
            tot = tot * a[i];
        }
    }
    cout<<tot<<endl;

    return 0;
}



Measured memory_bytes: 4336
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        double[] whxy=cin.ArrayDouble(4,0);
        double W=whxy[0];
        double H=whxy[1];
        double x=whxy[2];
        double y=whxy[3];
        int count=0;
        double menseki=W*H/2;
        if(x==W/2&&y==H/2)count=1;
        Console.WriteLine("{0} {1}",menseki,count);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public static void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }//Answer.IntArrayAns(x);
    public static void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 13268
#include <stdio.h>
#include <stdlib.h>
#define int long long

signed main(){
	int N, i, num[5] = {0, 0, 0, 0, 0};
	scanf("%lld", &N);
	int *a = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld", &a[i]);
		num[a[i] + 2]++;
	}
	num[2] = 0;
	num[3] = 0;
	if(num[0] % 2 == 0){
		num[1] = 0;
	}
	else{
		if(num[1] > 0){
			num[1] = 1;
		}
		else{
			num[0] = 2 * (num[0] / 2);
		}
	}
	printf("%d\n", num[0] + num[1] + num[2] + num[3] + num[4]);
	for(i = 0; i < N; i++){
		if(num[a[i] + 2] > 0){
			printf("%d\n", i + 1);
			num[a[i] + 2]--;
		}
	}
	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
string s;
i64 k;

/* include file*/
#include <functional>
#include <vector>
using namespace std;

template <class Monoid>
struct Segment {
  using Func = function<Monoid(Monoid, Monoid)>;

  vector<Monoid> node;
  Monoid ide;
  int n = 1;

  Func bin_f;
  Func update_f;

  Segment(const vector<Monoid>& init, Monoid ide_, Func f_, Func u_f)
    : bin_f(f_), ide(ide_), update_f(u_f) {
      int sz = init.size();
      while (n < sz) n *= 2;
      node.assign(n * 2 - 1, ide);
      for (int i = 0; i < sz; i++) node[i + n - 1] = init[i];
      for (int i = n - 2; i >= 0; i--)
        node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
    }

  void update(int i, Monoid x) {
    i += n - 1;
    node[i] = update_f(node[i], x);
    while (i) {
      i = (i - 1) / 2;
      node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
    }
  }

  Monoid get_inter(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (a <= l && r <= b) return node[k];
    if (r <= a || b <= l) return ide;

    Monoid lm = get_inter(a, b, k * 2 + 1, l, (l + r) / 2);
    Monoid rm = get_inter(a, b, k * 2 + 2, (l + r) / 2, r);
    return bin_f(lm, rm);
  }
};

// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730414#1
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730425#1

priority_queue<int,vector<int>,greater<int>> que[26];
int main(){
  cin >> s;
  cin >> k;

  int N = s.size();

  Segment<i64> seg(vector<i64>(202020,0),0,[](i64 a,i64 b){return a + b;},[](i64 a,i64 b){return a + b;});
  
  for(int i = 0;i < N;i++){
    int num = s[i] - 'a';
    que[num].push(i);
  
  }
  
  string ans = "";

  for(int i = 0;i < N;i++){
    for(int j = 0;j < 26;j++){
      if(que[j].empty()) continue;
      int idx = que[j].top();
      i64 a;
      if((a = idx + seg.get_inter(0,idx + 1) - i) > k) continue;
      k -= a;
      que[j].pop();
      ans.push_back((char)(j + 'a'));
      seg.update(0,1);
      seg.update(idx,-1);
      break;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 8868
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+3;
int pf[N],ar[N];
int main(){
	int n,k;cin >> n >> k;
	for(int i=0;i<n;i++) cin >> ar[i];
	while(k--){
		memset(pf,0,sizeof(pf));
		for(int i=0;i<n;i++){
			int dw = max(0,i-ar[i]);
			int up = min(n,i+ar[i]+1);
			pf[dw]++;
			pf[up]--;
		}
		for(int i=1;i<n;i++) pf[i] += pf[i-1];
		for(int i=0;i<n;i++) ar[i] = pf[i];
		int cnt = 0;
		for(int i=0;i<n;i++) if(ar[i] == n) cnt++;
		if(cnt == n) break;
	}
	for(int i=0;i<n;i++) cout << ar[i] << ' ';
	cout << '\n';
}

Measured memory_bytes: 5180
#include<stdio.h>
#include<string.h>
using namespace std;
char a[200050];
int main()
{
    while(~scanf("%s",a))
    {
        int pre=-1;
        int back=-1;
        int n=strlen(a);
        for(int i=0;i<n;i++)
        {
            if(a[i]=='A'&&pre==-1)pre=i;
            if(a[i]=='Z')back=i;
        }
        if(pre==-1||back==-1)
        {
            printf("0\n");
        }
        else printf("%d\n",back-pre+1);
    }
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

		String[] tmpArray = br.readLine().split(" ");

		int n = Integer.parseInt(tmpArray[0]);
		int q = Integer.parseInt(tmpArray[1]);

		int counter[] = new int[n + 1];
		int parent[] = new int[n + 1];
		int total[] = new int[n + 1];

		for(int i = 0; i < n - 1; i++){
			tmpArray = br.readLine().split(" ");

			int a = Integer.parseInt(tmpArray[0]);
			int b = Integer.parseInt(tmpArray[1]);

			parent[b] = a;
		}

		for(int i = 0; i < q; i++){
			tmpArray = br.readLine().split(" ");

			int p = Integer.parseInt(tmpArray[0]);
			int x = Integer.parseInt(tmpArray[1]);

			counter[p] += x;
		}

		for(int i = 1; i <= n; i++){
			if(i != 1){
				System.out.print(" ");
			}

			int result = 0;

//			int index = i;
//			while(index != 0){
//				result += counter[index];
//				index = parent[index];
//			}

			result += counter[i];
			result += total[parent[i]];
			total[i] = result;

			System.out.print(result);
		}
		System.out.println();
	}

}


Measured memory_bytes: 96804