akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String s = sc.next();
		String t = sc.next();
      	String log[] = s.split("");
        String tmt;
        String ans;
        int i;
        int count = 1;
		if(s.equals(t)){
           System.out.println("Yes");
           System.exit(0);
        }
      	
        while(count != s.length()){
            tmt = log[s.length() - 1];
     		for(i = s.length() - 2; i >= 0; i --){
          		log[i + 1] = log[i];         
        	}
          	log[0] = tmt;
          
          	StringBuilder sb = new StringBuilder();
            for(i=0;i <s.length(); i++){
              sb.append(log[i]);
              }
            ans = sb.toString();
            if(ans.equals(t)){
              System.out.println("Yes");
              System.exit(0);
            }
            count += 1;
        }
              System.out.println("No");        
    }
}

Measured memory_bytes: 36236
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>

using namespace std;

int main(void) {
	string s,t;

	cin>>s;
	t=s;

	int mina=0,minb=0;

	for (int i = 0; i < s.size(); i++) {
		if(i==0){
			if(s[i]=='1'){
				s[i]='0';
				mina++;
			}
		}else{
			if(s[i]=='0'){
				if(s[i-1]=='0'){
					s[i]='1';
					mina++;
				}
			}else{
				if(s[i-1]=='1'){
					s[i]='0';
					mina++;
				}
			}
		}
	}

	for (int i = 0; i < s.size(); i++) {
		if(i==0){
			if(t[i]=='0'){
				t[i]=1;
				minb++;
			}
		}else{
			if(t[i]=='0'){
				if(t[i-1]=='0'){
					t[i]='1';
					minb++;
				}
			}else{
				if(t[i-1]=='1'){
					t[i]='0';
					minb++;
				}
			}
		}
	}


	cout<<min(mina,minb)<<"\n";

	return 0;
}


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
#define dpair pair<double,double>

template <typename Val>
Val gcd(Val a, Val b) {
//use ll or int for gcd
    if (b==0) return a;
    else return gcd(b, a%b);
}
template <typename Val>
Val vec_max(vector<Val> v){
  return *max_element(v.begin(),v.end());
}
template <typename Val>
Val vec_min(vector<Val> v){
  return *min_element(v.begin(),v.end());
}
template <typename Val>
void show_vec(vector<Val> *v){
  cout<<endl;
  rep(i,v->size()){
    cout<<v->at(i)<<" ";
  }
  cout<<endl;
}
//---------------------------------------------------------------
int main(){
  vector<int> x(5);
  int ans;
  rep(i,5){
    cin>>x.at(i);
    if(x.at(i)==0)ans = i+1;
  }



  cout<<ans<<endl;




}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long x, ans = 0, a = 0;
  cin >> n >> x;
  vector<long long> vec(n);
  for (auto i = 0; i < n; i++) {
    cin >> vec[i];
  }
  if (vec[0] > x) {
    ans = vec[0] - x;
    vec[0] = x;
  }
  for (auto i = 0; i < n-1; i++) {
    if ((vec[i] + vec[i+1]) > x) {
      a = (vec[i] + vec[i+1]) - x;
      ans += a;
      vec[i+1] -= a;
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n;
  cin >> n;
  ll tmp = n;
  Ml use;

  for(ll i = 2; i * i <= n; i++) {
    if (tmp % i == 0) {
      while(tmp % i == 0) {
        use[i]++;
        tmp /= i;
      }
    }
  }
  if (tmp != 1) use[tmp]++;
  ll ans = 0;

  for(auto itr = use.begin(); itr != use.end(); ++itr) {
    // cout << itr->first <<" " << itr->second << endl;
    ll i = 1;
    while(i <= itr->second) {
      ans++;
      itr->second -= i;
      i++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main(){

  int A, B, C, K;
  cin >> A >> B >> C >> K;
  
  if(K <= A) cout << K << endl;
  else if(K <= A + B) cout << A << endl;
  else cout << 2 * A - K + B << endl;
}
  

Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

struct TCard;
void InputCards(int& Count,std::vector<TCard>& Cards);
void OutputCards(const std::vector<TCard>& Cards);
std::string BubbleSortCards(std::vector<TCard>& Cards);
std::string SelectionSortCards(std::vector<TCard>& Cards);
std::string IsStable(const std::vector<TCard>& Cards,const std::vector<TCard>& OriginalCards);

struct TCard
{
	char Suit;
	int Value;
	
	bool operator<(const TCard& Other)const;
	bool operator==(const TCard& Other)const;
};

int main()
{
	int Count = 0;
	std::vector<TCard> Cards;
	InputCards(Count,Cards);
	std::vector<TCard> CardsCopy = Cards;
	
	std::string Result = BubbleSortCards(Cards);
	OutputCards(Cards);
	std::cout << Result << std::endl;
	
	Result = SelectionSortCards(CardsCopy);
	OutputCards(CardsCopy);
	std::cout << Result << std::endl;
	
	return 0;
}

void InputCards(int& Count,std::vector<TCard>& Cards)
{
	std::cin >> Count;
	for(int i=0;i<Count;i++)
	{
		TCard TempCard;
		char Suit = 0;
		std::cin >> Suit;
		TempCard.Suit = Suit;
		int Value = 0;
		std::cin >> Value;
		TempCard.Value = Value;
		Cards.push_back(TempCard);
	}
}

void OutputCards(const std::vector<TCard>& Cards)
{
	for(unsigned int i=0;i<Cards.size();i++)
	{
		std::cout << Cards[i].Suit << Cards[i].Value << std::flush;
		if(i != Cards.size() - 1)
		{
			std::cout << " " << std::flush;
		}else{
			std::cout << std::endl;
		}
	}
}

std::string BubbleSortCards(std::vector<TCard>& Cards)
{
	std::vector<TCard> OriginalCards = Cards;
	for(unsigned int i = 0;i<Cards.size();i++)
	{
		for(unsigned int j = Cards.size() - 1;j > i;j--)
		{
			if(Cards[j].Value < Cards[j-1].Value)
			{
				std::swap(Cards[j],Cards[j-1]);
			}
		}
	}
	return IsStable(Cards,OriginalCards);
}

std::string SelectionSortCards(std::vector<TCard>& Cards)
{
	std::vector<TCard> OriginalCards = Cards;
	for(unsigned int i = 0;i<Cards.size();i++)
	{
		unsigned int Min = i;
		for(unsigned int j = i;j<Cards.size();j++)
		{
			if(Cards[j].Value < Cards[Min].Value)
			{
				Min = j;
			}
		}
		std::swap(Cards[i],Cards[Min]);
	}
	return IsStable(Cards,OriginalCards);
}

std::string IsStable(const std::vector<TCard>& Cards,const std::vector<TCard>& OriginalCards)
{
	std::vector<TCard> StableCards = OriginalCards;
	std::stable_sort(StableCards.begin(),StableCards.end());

	if(Cards == StableCards) return "Stable";
	return "Not stable";
}

bool TCard::operator<(const TCard& Other)const
{
	if(Value < Other.Value) return true;
	return false;
}

bool TCard::operator==(const TCard& Other)const
{
	if(Suit == Other.Suit && Value == Other.Value) return true;
	return false;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h> 
#define ll long long int
#define ld long double
#define maxim (ll)1000000000000
#define PB push_back
#define MP make_pair
using namespace std;
vector<ll> prime;
bool sortbysecond(const pair<ll,ll> &a,const pair<ll,ll> &b)
{ 
if(a.second<b.second)
return true;
else
 return false;
}
void sieve()
{
 bool ifprime[1000001];
 for(ll i=0;i<1000001;i++)
  ifprime[i]=true;
 ifprime[0]=ifprime[1]=false;
 for(ll i=2;i<=1000000;i++){
 	if(ifprime[i]){
 		prime.PB(i);
 		for(ll j=i*i;j<=100000;j+=i)
 		 ifprime[j]=false;
 	}
 }	
}
int main()
{

ios::sync_with_stdio(0);
cin.tie(0);
ll t=1;
//cin>>t;
while(t--)
{
 sieve();
 ll a,b,c=1;
 cin>>a>>b;
 ll g=__gcd(a,b);
 for(ll i:prime)
 {
  if(g%i==0)
   c++;
  while(g%i==0)
   g/=i;
 }
 if(g!=1)
  c++;
 cout<<c<<"\n";
}
return 0;
}

Measured memory_bytes: 11628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=1000000000+5;
const int N=5000+5;
const ll oo=1e18+5;
const ll mod=998244353;

int n;
int dp[2005][2005];

void max_self(int& a,int b){
	if(b>a) a=b;
}

void update(int i,int j,int val){
	max_self(dp[i][j],val);
	max_self(dp[j][i],val);
	max_self(dp[i][n],val);
	max_self(dp[n][i],val);
	max_self(dp[j][n],val);
	max_self(dp[n][j],val);
	max_self(dp[n][n],val);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	int n3=n*3;
	vector<int> a(n3);
	for(int& x:a) cin>>x,--x;
	int m=n+1;
	for(int i=0;i<m;++i){
		for(int j=0;j<m;++j) dp[i][j]=-INF;
	}
	update(a[0],a[1],0);
	int add=0;
	for(int i=2;i<n3-1;i+=3){
		int x=a[i],y=a[i+1],z=a[i+2];
		if(x==y&&y==z){
			++add;
			continue;
		}
		vector<tuple<int,int,int>> vec;
		for(int times=0;times<3;++times){
			{
				for(int aa=0;aa<m;++aa){
					int now=dp[aa][n];
					if(y==z){
						max_self(now,dp[aa][y]+1);
					}
					vec.emplace_back(aa,x,now);
				}
			}
			{
				int now=max(dp[n][n],dp[z][z]+1);
				vec.emplace_back(x,y,now);
			}
			swap(x,y);
			swap(y,z);
		}
		for(tuple<int,int,int> x:vec){
			int i,j,val;
			tie(i,j,val)=x;
			update(i,j,val);
		}
	}
	int ans=dp[n][n];
	int l=a[n3-1];
	max_self(ans,dp[l][l]+1);
	ans+=add;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 19444
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, T = map(int, input().split())
    A = list(map(int, input().split()))
    A_ = sorted(A)

    j = -1
    diff = 0
    cnt = 0
    MAX = [0] * N
    MAX[-1] = A[-1]
    for i in range(N - 1)[::-1]:
        if A[i] > MAX[i + 1]:
            MAX[i] = A[i]
        else:
            MAX[i] = MAX[i + 1]

    diff = 0
    cnt = 0
    for i in range(N):
        if MAX[i] - A[i] > diff:
            diff = MAX[i] - A[i]
            cnt = 1
        elif MAX[i] - A[i] == diff:
            cnt += 1

    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14480
#include <iostream>
#include <queue>
#include <utility>
 
#define rep(i,n) for(int i = 0; i < n; i++)
 
using namespace std;
 
const int INF = 1e9;
 
int main(){
  int H, W;
  cin >> H >> W;
  
  int D[H][W];
  rep(i,H) fill(D[i], D[i]+W, INF);
  
  queue<pair<int,int> > que;
  rep(i,H){
    rep(j,W){
      char c;
      cin >> c;
      if(c == '#'){
        que.push(make_pair(i,j));
        D[i][j] = 0;
      }
    }
  }
  
  while(!que.empty()){
    pair<int,int> p = que.front();
    que.pop();
    
    int dy[] = {1,-1,0,0};
    int dx[] = {0,0,1,-1};
    
    rep(m,4){
      int y = p.first + dy[m];
      int x = p.second + dx[m];
      if(y < 0 || H <= y || x < 0 || W <= x || D[y][x] != INF) continue;
      D[y][x] = D[p.first][p.second] + 1;
      que.push(make_pair(y,x));
    }	
  }
  
  int ans = 0;
  rep(n,H){
    rep(o,W){
      ans = max(ans,D[n][o]);
    }
  }
  cout << ans;
}

Measured memory_bytes: 12304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+9, LINF = 1e18;

int main(){
    ll n,ans=0;
    cin>>n;
    for(int a=1;a<=n;a++)for(int b=1;b<=n;b++)for(int c=1;c<=n;c++)ans+=gcd(gcd(a,b),c);
    cout<<ans<<endl;
}

Measured memory_bytes: 3652
#include<deque>
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/
const int N=5050;

int n;
char s[N],t[N];

deque<int> A,B;

int main(){
    scanf("%d",&n);
    scanf("%s",s+1);
    scanf("%s",t+1);
    FOR(i,1,n)s[i]-='0',t[i]-='0';

    s[0]=!s[1],t[0]=!t[1];
    s[n+1]=!s[n],t[n+1]=!t[n];

    FOR(i,1,n+1)if(s[i-1]!=s[i])A.push_back(i);
    FOR(i,1,n+1)if(t[i-1]!=t[i])B.push_back(i);
    if(s[1]!=t[1])A.push_front(1);
    for(int i=0;i<=n+1;i+=1)A.push_front(1),A.push_front(1);
    for(int i=0;i<=n+1;i+=1)A.push_back(n+1),A.push_back(n+1);
    //for(int i=0;i<A.size();i++)printf("%d ",A[i]); puts("");
    //for(int i=0;i<B.size();i++)printf("%d ",B[i]); puts("");
    int ans=1e9;
    for(int i=0;i+B.size()<=A.size();i+=2){
        int tot=0;
        for(int j=0;j<i;j++)tot+=abs(A[j]-1);//全放左边
        for(int j=0;j<B.size();j++){
            tot+=abs(A[i+j]-B[j]);
        }
        for(int j=i+B.size();j<A.size();j++)tot+=abs(A[j]-(n+1));//全放右边
        ans=min(ans,tot);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 512
n,k,q=map(int,input().split())
A=[int(input()) for i in range(q)]

tokuten=[0]*n

for i in range(q):
    tokuten[A[i-1]-1]=tokuten[A[i-1]-1]+1

for i in range(n):
    if tokuten[i]>q-k:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 8592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
    std::fill((T *)array, (T *)(array + N), val);
}

int main()
{
    int n, k;
    cin >> n >> k;
    map<int, int> mp;
    repi(i, k, 0)
    {
        int d;
        cin >> d;
        repi(j, d, 0)
        {
            int a;
            cin >> a;
            mp[a]++;
        }
    }
    cout << n -mp.size() << endl;
    return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int num1 = 0, num2 = 0;
		for(int i=0; i<s.length(); i++){
			if(s.charAt(i)=='A'){
				num1 = i;
				break;
			}
		}
		for(int i=s.length()-1; i>=0; i--){
			if(s.charAt(i)=='Z'){
				num2 = i;
				break; 
			}
		}
		System.out.println(num2-num1+1);
	}
}

Measured memory_bytes: 26508
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    String q ="";
    if(a==b){
      q="Draw";
    }else if(a==1){
      q="Alice";
    }else if(b==1){
      q="Bob";
    }else if(a>b){
      q="Alice";
    }else{
      q="Bob";
    }
    System.out.println(q);

  }
  

  
}


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

typedef struct {
	long step;
	long connected;
} S_VERTICE;

int main(void) {

  long n,m;
  scanf("%ld %ld", &n, &m);
  long **tree;
  tree = (long **)malloc(sizeof (long*) * (n+1));
  for (long i = 0; i < n+1; i++) {
    tree[i] = (long *)malloc(sizeof (long) * (m+1));
    tree[i][0] = 0;
  }
  for (long i = 1; i <= n; i++) {
    tree[0][i] = 0;
  }
  long a,b;
  for (long i = 0; i < m; i++) {
    scanf("%ld %ld", &a, &b);
    tree[a][0]++;
    tree[a][tree[a][0]] = b;
    tree[b][0]++;
    tree[b][tree[b][0]] = a;
  }
  S_VERTICE vertices[n+1];
  for (long i = 1; i <= n; i++) {
		vertices[i].step = -1;
    vertices[i].connected = -1;
  }
	vertices[1].step = 1;
	vertices[1].connected = 0;

	long visited[n];
	visited[0] = 1;
	long head = 0;
	long tail = 0;
	long tmp_tail;
  long cur;
  while (1) {
		tmp_tail = tail;
    for (long i = head; i <= tail; i++) {
			cur = visited[i];
    	for (long j = 1; j <= tree[cur][0]; j++) {
				if (vertices[tree[cur][j]].connected != -1) {
					continue;
				}
    		vertices[tree[cur][j]].step = vertices[cur].step+1;
				vertices[tree[cur][j]].connected = cur;
				tmp_tail++;
				visited[tmp_tail] = tree[cur][j];
    	}
    }
		head = tail+1;
		tail = tmp_tail;
		if (tail == n-1) {
			break;
		}
  }
	free(tree);

	printf("Yes\n");

  for (long i = 2; i <= n; i++) {
    printf("%ld \n", vertices[i].connected);
  }

  return 0;
}


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

using namespace std;

using int64 = long long;
const int64 INF = 1LL << 60;

int64 beet(int64 y, int64 x) {
  int64 ret = INF;
  for(int i = 1; i < y; i++) {
    if(x >= 2) {
      int64 beet1 = i * x;
      int64 beet2 = (x / 2) * (y - i);
      int64 beet3 = (x - (x / 2)) * (y - i);

      auto res = minmax({beet1, beet2, beet3});
      ret = min(ret, res.second - res.first);
    }

    if((y - i) >= 2) {
      auto luz1 = i * x;
      auto luz2 = (y - i) / 2 * x;
      auto luz3 = ((y - i) - (y - i) / 2) * x;

      auto res = minmax({luz1, luz2, luz3});
      ret = min(ret, res.second - res.first);
    }
  }
  return (ret);
}

int main() {
  int H, W;
  cin >> H >> W;
  cout << min(beet(H, W), beet(W, H)) << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  vector<long> sum_(1001, 0);
  repd(i, 1, 1001){
    sum_[i] = sum_[i-1] + i;
  }
  int n, k;
  cin >> n >> k;
  vector<double> p(n);
  rep(i, n){
    double p_tmp;
    cin >> p_tmp;
    p[i] = sum_[p_tmp] / p_tmp;
  }

  double between = 0.0;
  rep(i, k){
    between += p[i];
  }
  double ans = between;
  repd(i, k, n){
    between -= p[i-k];
    between += p[i];
    if(between > ans){
      ans = between;
    }
  }

  printf("%.10lf\n", ans);
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    int A, B, T;
    cin >> A >> B >> T;
    
    int res = 0;
    for (int i = 1; i < T + 1; ++i) {
        if (i % A == 0) res += B;
    }
    cout << res << endl;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> edge(N);
    vector<int> into(N, 0);
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        edge[x].push_back(y);
        into[y]++;
    }
    
    queue<int> q;
    for (int i = 0; i < N; i++) {
        if (into[i] == 0) q.push(i);
    }
    vector<int> dp(N, 0);
    int ans = 0;
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        ans = max(ans, dp[now]);
        for (int nxt : edge[now]) {
            dp[nxt] = max(dp[nxt], dp[now]+1);
            into[nxt]--;
            if (into[nxt] == 0) q.push(nxt);
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 9384
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args){
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		long res = 0;
		for(int i=0;i<N;i++){
			res += sc.nextInt() - 1;
		}
		out.println(res);
		out.flush();
	}
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 23508
#include<iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int main() {
  int n, a[5010], sum[5010], res;
  while (true) {
    cin >> n;
    if (n == 0) break;
    rep (i, n) cin >> a[i];
    sum[0] = 0;
    rep (i, n) sum[i + 1] = a[i] + sum[i];
    res = -1000000000;
    rep (i, n) rep (j, i + 1) {
      res = max(res, sum[i + 1] - sum[j]);
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 1192
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define F first
#define S second
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
const int loose = 0;
const int tight = 1;


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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void Dijkstra(Graph& G, ll s, Array& d) {//O(|E|log|V|)
	d.resize(G.size());
	REP(i, d.size())d[i] = INF;
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P>> q;
	q.push(make_pair(0, s));
	while (!q.empty()) {
		P a = q.top();
		q.pop();
		if (d[a.second] < a.first)continue;
		REP(i, G[a.second].size()) {
			Edge e = G[a.second][i];
			if (d[e.to] > d[a.second] + e.cap) {
				d[e.to] = d[a.second] + e.cap;
				q.push(make_pair(d[e.to], e.to));
			}
		}
	}
}

ll digit_DP(string s) {
	ll n = s.size();
	Matrix dp(n + 1, Array(2, 0));
	dp[0][tight] = 1;
	REP(i, n) {
		ll ni = i + 1;
		if (s[i] == '0') {
			(dp[ni][tight] += dp[i][tight]) %= MOD;//0,0のみ
			(dp[ni][loose] += 3*dp[i][loose]%MOD) %= MOD;//0,0 1,0 0,1
		}
		else {
			(dp[ni][loose] += dp[i][loose] * 3 % MOD) %= MOD;
			(dp[ni][loose] += dp[i][tight]) %= MOD;//0,0
			(dp[ni][tight] += dp[i][tight] * 2 % MOD) %= MOD;//0,1 1,0
		}
	}

	return  (dp[n][loose] + dp[n][tight]) % MOD;
}

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

	string L;
	cin >> L;
	cout << digit_DP(L) << endl;
	return 0;
}

Measured memory_bytes: 5968
class Position():
    def __init__(self, posi, dist):
        self.pos = posi
        self.d   = dist


    def is_talk(self, tar_pos):
        if abs(self.pos - tar_pos) <= self.d:
            return True
        else:
            return False
    


if __name__ == '__main__':
    a, b, c, d  = [int(_) for _ in input().split()]
    p1 = Position(a, d)
    p2 = Position(b, d)
    p3 = Position(c, d)
    if p1.is_talk(p3.pos):
        print("Yes")
    elif p1.is_talk(p2.pos) and p2.is_talk(p3.pos):
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3064
<?php

while (true) {
    fscanf(STDIN, '%d %d', $height, $width);
    if ($height == 0 && $width == 0) break;
    
    $rentangle = new Rectangle($height, $width);
    Drawer::drawObject($rentangle);
    
}

class Rectangle
{
    private $height;
    private $width;
    private $frameChar  = '#';
    private $insideChar = '.';
    
    
    public function __construct($height, $width)
    {
        $this->height = $height;
        $this->width  = $width;
    }
    
    public function draw()
    {
        for ($i = 1; $i <= $this->height; $i++) {
            if ($i == 1 || $i == $this->height) {
                $this->drawTopAndBottomLine();
            } else {
                $this->drawMiddleLine();
            }
        }
    }
    
    public function drawTopAndBottomLine()
    {
        echo str_repeat($this->frameChar, $this->width), PHP_EOL;
    }
    
    public function drawMiddleLine()
    {
        echo $this->frameChar, str_repeat($this->insideChar, $this->width - 2), $this->frameChar, PHP_EOL;
    }
}

class Drawer
{
    public static function drawObject($object)
    {
        $object->draw();
        Self::drawEmptyLine();
    }
    
    public static function drawEmptyLine()
    {
        echo PHP_EOL;
    }
}

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

bool LinearSearch(int A[],int key,int n){
    for(int i = 0 ; i < n-1; i++){
        if(A[i] == key) return true;
    }
    return false;
    

}


int main(){
    int n,q;
    int s[10000],t[10000];
    
    cin >> n;// 配列S
    for(int i = 0; i < n; i++){
        cin >> s[i];
        //cout << "S " << s[i].S << endl;
    }
    
    //配列T
    cin >> q;
    for(int i = 0; i < q; i++){
        scanf("%d", &t[i]);
        //printf("T %s\n", t[i].T);
        //cout << LinearSearch(s[i].S, key[i].T, q);
        
    }
    
    int count = 0;
    for(int k = 0; k < q;k++){
        if(LinearSearch(s, t[k], n))  count++;
    }
    cout << count <<endl;
    
    
    
    
    return 0;
}



Measured memory_bytes: 3200
// https://atcoder.jp/contests/abc136/tasks/abc136_e
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn isok(a: &Vec<i32>, d: i32, k: i32) -> bool {
    let n = a.len();
    let mut modulo = vec![];
    for ai in a {
        if ai % d >= 1 {
            modulo.push(ai%d);
        }
    }
    modulo.sort();

    let n = modulo.len();
    let mut sum = vec![0; n+1];
    for i in 0..n {
        sum[i+1] = sum[i] + modulo[i];
    }

    for w in 1..n {
        let mut dw = sum[w];
        let mut up = ((n-w) as i32) * d - (sum[n] - sum[w]);
        if dw == up && dw <= k {
            return true;
        }
    }
    false
}

fn main() {
    input! {
        n: usize, k: i32,
        a: [i32; n]
    };
    let sum = a.iter().fold(0, |a,c| a+c);

    let mut divisors = vec![];
    for w in 1..sum+1 {
        if w * w >= sum {
            if w * w == sum {
                divisors.push(w);
            }
            break;
        }
        if sum % w == 0 {
            divisors.push(sum/w);
            divisors.push(w);
        }
    }
    divisors.sort();
    divisors.reverse();

    let mut ans = 1;
    for d in divisors {
        if isok(&a, d, k) {
            ans = d;
            break;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<cstdio>
int main(){
	bool a[100001]={};
	for(int i=2;i<=100000;i++){
		a[i]=true;
	}
	a[0]=false;
	a[1]=false;
	for(int i=2;i<=100000;i++){
		if(a[i]==true){
			for(int j=i*2;j<=100000;j+=i){
				a[j]=false;
			}
		}
	}
	int b[50000]={};
	b[0]=0;
	for(int i=1;i<50000;i++){
		b[i]=b[i-1];
		if(a[2*i+1]&&a[i+1])b[i]++;
	}
	int q;
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		l=(l-1)/2;
		if(l==0)l++;
		r=(r-1)/2;
		printf("%d\n",b[r]-b[l-1]);
	}
	return 0;
}
		

Measured memory_bytes: 896
#include <stdio.h>
int main(void)
{
	int n,a[201][4],b=0,i,j,k;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	for(j=1;j<=3;j++)scanf("%d",&a[i][j]);
	for(i=1;i<=3;i++){
		for(j=1;j<=n;j++){
			for(k=1;k<=n;k++){
				if(a[j][i]==a[k][i]&&j!=k){
					a[k][i]=0;
					b=1;
				}
			}
			if(b==1)a[j][i]=b=0;
		}
	}
	for(i=1;i<=n;i++)printf("%d\n",a[i][1]+a[i][2]+a[i][3]);
	return 0;
}



Measured memory_bytes: 2036
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
    int R[MAX], n;
    
    cin >> n;
    for(int i = 0; i < n; i++) cin >> R[i];
    
    int maxv = -2000000000;
    int minv = R[0];
    
    for(int i = 1; i < n; i++){
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    
    cout << maxv << endl;
    
    return 0;
}


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

using ll = long long;
using namespace std;

int main() {
    string s;
    cin >> s;
    int n = (int)s.size();
    string s1 = s.substr(0, (n - 1)/2);
    string s2 = s.substr((n + 1)/2, (n - 1)/2);
    string rev = s;
    string rev1 = s1;
    string rev2 = s2;
    reverse(rev.begin(), rev.end());
    reverse(rev1.begin(), rev1.end());
    reverse(rev2.begin(), rev2.end());
    if (rev1 == s1 && rev2 == s2 && rev == s) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

#define MAX_N 100000
#define INF 1000000000

typedef struct {
	int to, dist;
}P;

P graph[MAX_N][16];
int graphptr[MAX_N];

int n;

typedef struct {
	int prior;
	P data;
} node_t;

typedef struct {
	node_t *nodes;
	int len;
	int size;
} heap_t;

void push(heap_t *h, int prior, P data) {
	if (h->len + 1 >= h->size) {
		h->size = h->size ? h->size * 2 : 4;
		h->nodes = (node_t*)realloc(h->nodes, h->size * sizeof(node_t));
	}
	int i = h->len + 1;
	int j = i / 2;
	while (i > 1 && h->nodes[j].prior > prior) {
		h->nodes[i] = h->nodes[j];
		i = j;
		j /= 2;
	}
	h->nodes[i].prior = prior;
	h->nodes[i].data = data;
	h->len++;
}

P pop(heap_t *h) {
	int i, j, k;
	if (!h->len) {
		P p;
		p.to = -1; p.dist = -1;
		return p;
	}
	P data = h->nodes[1].data;
	h->nodes[1] = h->nodes[h->len];
	h->len--;
	i = 1;
	while (true) {
		k = i;
		j = 2 * i;
		if (j <= h->len && h->nodes[j].prior < h->nodes[k].prior) k = j;
		if (j + 1 <= h->len && h->nodes[j + 1].prior < h->nodes[k].prior)k = j + 1;
		if (k == i)break;
		h->nodes[i] = h->nodes[k];
		i = k;
	}
	h->nodes[i] = h->nodes[h->len + 1];
	return data;
}

int cost[MAX_N];

void dijkstra(int k) {
	heap_t *h = (heap_t*)calloc(1, sizeof(heap_t));
	for (int i = 0; i < n; ++i)cost[i] = INF;
	cost[k] = 0;
	P t;
	t.to = k, t.dist = 0;
	push(h, t.dist, t);
	while (h->len) {
		P p = pop(h);
		int v = p.to;
		if (cost[v] < p.dist)continue;
		for (int i = 0; i < graphptr[v]; ++i) {
			P e = graph[v][i];
			if (cost[e.to] > cost[v] + e.dist) {
				cost[e.to] = cost[v] + e.dist;
				P m;
				m.to = e.to; m.dist = cost[e.to];
				push(h, m.dist, m);
			}
		}
	}
}

int treeDim_C(P *ret) {
	dijkstra(0);

	int maxV = -INF, maxI;
	for (int i = 0; i < n; ++i) {
		if (cost[i] > maxV)maxV = cost[i], maxI = i;
	}

	dijkstra(maxI);

	ret->to = maxI;

	maxV = -INF, maxI;
	for (int i = 0; i < n; ++i) {
		if (cost[i] > maxV)maxV = cost[i], maxI = i;
	}

	ret->dist = maxI;
	return maxV;
}

int main(void) {
	scanf("%d", &n);
	for (int i = 0; i < n - 1; ++i) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);

		graph[a][graphptr[a]].to = b;
		graph[a][graphptr[a]++].dist = c;

		graph[b][graphptr[b]].to = a;
		graph[b][graphptr[b]++].dist = c;
	}

	P p;
	printf("%d\n", treeDim_C(&p));

	return 0;
}

Measured memory_bytes: 14324
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority queue
#include<deque>//double_ended queue
using namespace std;
int main()
{ 
    int n;
    cin>>n;
    long long int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int ans=0;
    long long int max=0;
    while(a[ans+1]<a[n-1]/2){ans++;}
    if(a[n-1]%2==0){
        if(a[ans+1]-a[n-1]/2<a[n-1]/2-a[ans]){
            ans++;
        }
    }
    else{
        if(a[ans+1]-(a[n-1]+1)/2<(a[n-1]-1)/2-a[ans]){
            ans++;
        }
    }
    if(a[0]>=a[n-1]/2){ans=a[0];}
    cout<<a[n-1]<<' '<<a[ans]<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define dl double long
const int INF=0x3fffffff;
const ll MOD=1000000007;
const ll MODD=998244353;
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
ll gcd(ll a, ll b) { return (b > 0) ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a*b/gcd(a, b); }
using ipair = pair<ll, ll>;

int main()
{
  ll K, A, B;
  cin >> K >> A >> B;  
  REP(i, A, B+1){
    if(i%K==0){
      cout << "OK" << "\n";
      return(0);
    }
  }
  cout << "NG" << "\n";
}


Measured memory_bytes: 3684
s = list(map(int, input().split(" ")))
n = s[0]
c = s[1]
ans = 0

for v in range(n+1):
    x = v
    for i in range(n+1):
        y = i
        if  0 <= (c - x - y) <= n:
                ans += 1
print(ans) 

Measured memory_bytes: 3060
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#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 EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

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

int grid[110][110];
vector<string> field;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);

    int H, W;
    cin >> H >> W;
    for (int i = 0; i < H; ++i)
    {
        string s;
        cin >> s;
        field.push_back(s);
    }

    for (int i = 0; i < H; ++i)
    {
        int cl = -1;
        for (int j = 0; j < W; ++j)
        {
            if (field[i][j] == 'c')
            {
                cl = 0;
            }

            grid[i][j] = cl;
            if (cl != -1)
                cl++;
        }
    }

    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
        {
            if(j)
                cout << " ";
            cout << grid[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3284
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)

#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define op(i) cout << (i) << endl;
#define F first
#define S second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;


int main()
{
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    vector<pll> ans(n - 1);
    ll m;
    if (a[0]>=0){
        ll x = a[0];
        rep(i,n-2){
            ans[i] = mp(x, a[1 + i]);
            x -= a[1 + i];
        }
        ans[n - 2] = mp(a[n - 1], x);
        m = a[n - 1] - x;
    }
    else if (a[n-1]<=0){
        ll x = a[n - 1];
        rep(i,n-1){
            ans[i] = mp(x, a[i]);
            x -= a[i];
        }
        m = x;
    }
    else {
        sort(all(a), greater<ll>());
        ll idx = 0;
        ll x = a[n - 1];
        while (a[idx+1]>=0){
            ans[idx] = mp(x, a[idx]);
            x -= a[idx];
            idx++;
        }
        ans[idx] = mp(a[idx], x);
        x = a[idx] - x;
        repf(i,idx+1,n-1){
            ans[i] = mp(x, a[i]);
            x -= a[i];
        }
        m = x;
    }
    cout << m << endl;
    rep(i, n - 1) cout << ans[i].F << " " << ans[i].S << endl;
}


Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <map>
#include <numeric>
#include <queue>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
    vector<int> n(4);
    cin >> n[0] >> n[1] >> n[2] >> n[3];
    sort(n.begin(), n.end());
    if(n[0]==1 and n[1] == 4 and n[2] == 7 and n[3] == 9){
        cout << "YES"<< endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	int h, w, n; cin >> w >> h >> n;

	int l = 0, r = w;
	int d = 0, u = h;
	rep(i, 0, n) {
		int x, y, a;
		cin >> x >> y >> a;
		if (a == 1) l = max(l, x);
		if (a == 2) r = min(r, x);
		if (a == 3) d = max(d, y);
		if (a == 4) u = min(u, y);
	}
	cout << max(0, r - l) * max(0, u - d) << endl;
	return 0;
}


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

int main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= 9; ++i) {
		if (i * 111 >= n) {
			ans = i * 111;
			break;
		}
	}  
	cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,i,countt1=0,countt2=0,countt3=0,countt4=0;
    cin>>N;

    char ch[N];
    for(i=0;i<N;i++)
    {
        cin>>ch[i];
        if(ch[i]=='P') countt1++;
        if(ch[i]=='W') countt2++;
        if(ch[i]=='G') countt3++;
        if(ch[i]=='Y') countt4++;
    }
    if(countt1>=1) countt1=1;
    if(countt2>=1) countt2=1;
    if(countt3>=1) countt3=1;
    if(countt4>=1) countt4=1;

    if((countt1+countt2+countt3+countt4)==1) cout<<"One"<<endl;
    else if((countt1+countt2+countt3+countt4)==2) cout<<"Two"<<endl;
    else if((countt1+countt2+countt3+countt4)==3) cout<<"Three"<<endl;
    else if((countt1+countt2+countt3+countt4)==4) cout<<"Four"<<endl;

    return 0;
}


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

template<typename T>
istream& operator >> (istream& istr, vector<T>& vec){
    for(T& x: vec) istr >> x;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& vec){
    if(!vec.empty()){
        ostr << vec.front();
        for(auto itr = ++vec.begin(); itr != vec.end(); itr++)
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    ostr << p.first << " " << p.second;
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
// vll x(n); x[i]=a;
typedef vector<pair<ll,ll>> vpll;
// vpll x(n); x[i]={a,b}; x[i].first/second;
typedef vector<vector<ll>> vvll;
// vvll x(m,vi(n)); x[i][j]=a;

#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
// sort(all(x));

int main(){
    ll n, ans = 0;
    cin >> n;
    unordered_map<string, ll> box;

    REP(i,n){
        string s;
        cin >> s;
        sort(all(s));
        if(!(box.emplace(s,0).second)) box[s] += 1;
    }

    for(pair<string, ll> i:box) ans += i.second * (i.second+1) / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10660
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	string S;
	cin>>S;
	int N = S.size();
	vector<string> ans;
	for (int i = 0; i < N; ++i){
		for (int j = 0; i+j-1 < N; ++j){
			string s = S.substr(i,j);
			int cnt = 0;
			rep(k,j){
				if(s[k]=='A'||s[k]=='T'||s[k]=='G'||s[k]=='C')
					cnt++;
			}
			if(cnt==j)ans.push_back(s);
		}
	}
	sort(all(ans));
	int a = -1;
	rep(i,ans.size()){
		//cout<<ans[i]<<endl;
		//cout<<ans[i].size()<<endl;
		int b = ans[i].size();
		a = max(a ,b);
	}
	cout<<a<<endl;
}

Measured memory_bytes: 256
from bisect import bisect_left


def eratosthenes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False

    for i in range(2, int(n**0.5) + 1):
        if is_prime[i]:
            for j in range(i*2, n+1, i):
                is_prime[j] = False

    return is_prime


q = int(input())

p = eratosthenes(10 ** 5)
l = [0] * 10 ** 5
for i in range(3, 10 ** 5, 2):
    if p[i] and p[(i+1)//2]:
        l[i] = 1

sum_l = [0]
for v in l[1:]:
    sum_l.append(sum_l[-1] + v)

res = []
for _ in range(q):
    l, r = map(int, input().split())
    res.append(sum_l[r] - sum_l[l-1])

for v in res:
    print(v)

Measured memory_bytes: 84000
n=int(input())
d = {}
for i in range(26):
  d[chr(ord("a")+i)]=10**9
for i in range(n):
  s=input()
  for j in range(26):
    d[chr(ord("a")+j)]=min(d[chr(ord("a")+j)], s.count(chr(ord("a")+j)))

ans = ""
for e in d.items():
  ans+=e[0]*e[1]
print(ans)
  
  


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


int32_t main()
{ 
  int n;
  cin >> n;
  vector<int> v(n);
  
  for(int i = 0; i < n; i++)
    cin >> v[i];
    
  set<int> s;
  int cnt = 0;
  
  for(int i = 0; i < n; i++){
    s.insert(v[i]);
    if(*s.begin() >= v[i]) cnt++;
  }

  cout << cnt;
  return 0;
}


Measured memory_bytes: 10368
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<set>
#include<iomanip>
#include<cmath>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
string s;
int count(string t){
    int num = 0;
    for(int i = 1; i < t.size(); i++){
        if(s[i] == s[i-1]){
            num++;
            if(s[i-1] == '0') s[i] = '1';
            else s[i] = '0';
        }
    }
    return num;
}
int main(){
    cin >> s;
    int cnt = MM;
    if(s[0] == '0'){
        cnt = min(cnt,count(s));
        s[0] = '1';
        cnt = min(cnt, count(s)+1);
        cout << cnt << endl;
    } else {
        cnt = min(cnt,count(s));
        s[0] = '0';
        cnt = min(cnt, count(s)+1);
        cout << cnt << endl;
    }

}

Measured memory_bytes: 512