akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

inline int read(){
	char ch=getchar();int x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}

int a[10000000];

int main(){
	int n=read();
	long long sum=0;
	for(int i=1;i<=n;i++){
		a[i]=read();
	}
	int i=1,j=1;
	long long now=0;
	while(i<=n){
		while(j<=n && (now^a[j])==now+a[j]){
			now^=a[j++];sum++;
		}
		now^=a[i++];
		sum+=j-i;
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 1024
n = int(input())
MAXN = 110000

f_inf = float('inf')
dp = [f_inf] * (MAXN+n)

dp[0] = 0

for i in range(1, n+2):
    for j in range(7):
        dp[i] = min(dp[i], dp[i-pow(6, j)]+1)
    for k in range(6):
        dp[i] = min(dp[i], dp[i-pow(9, k)]+1)

print(dp[n])

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

int main() {
    int N;
    cin >> N;
    vector<queue<int>> A(N, queue<int>());
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N - 1; j++) {
            int a;
            cin >> a;
            a--;
            A[i].push(a);
        }
    }

    queue<int> que1;
    for (int i = 0; i < N; i++) {
        que1.push(i);
    }

    int cnt = 0;
    bool updated = true;

    queue<int> que2;
    while (updated) {
        updated = false;
        vector<bool> used(N, false);
        while (!que1.empty()) {
            int i = que1.front(); que1.pop();
            if (!used[i] && !A[i].empty()) {
                int j = A[i].front();
                if (!used[j] && !A[j].empty() && A[j].front() == i) {
                    updated = true;
                    A[i].pop(); A[j].pop();
                    que2.push(i); que2.push(j);
                    used[i] = true; used[j] = true;
                }
            }
        }

        if (updated) cnt++;
        swap(que1, que2);
    }

    for (int i = 0; i < N; i++) {
        if (!A[i].empty()) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdlib.h>
#define ll long long
#define MOD_P 1000000007
using namespace std;



int main()
{
	int a, b, c, tmp;

	cin >> a >> b >> c;

	tmp = c;
	c = b;
	b = a;
	a = tmp;

	printf("%d %d %d", a, b, c);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

void print(const vector<int>& A) {
    for (int i = 0; i < A.size(); i++) {
        if (i == 0) {
            cout << A[i];
        } else {
            cout << ' ' << A[i];
        }
    }
    cout << endl;
}

void bubbleSort(vector<int>& A) {
    auto flag = true;
    auto swaps = 0;
    while (flag) {
        flag = false;
        for (auto j = A.size() - 1; j > 0; j--) {
            if (A[j] < A[j - 1]) {
                swap(A[j], A[j - 1]);
                flag = true;
                swaps++;
            }
        }
    }
    print(A);
    cout << swaps << endl;
}

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;

    vector<int> a;
    a.reserve(n);

    for (int i = 0; i < n; i++) {
        int val;
        cin >> val;
        a.push_back(val);
    }

    bubbleSort(a);

    return 0;
}

Measured memory_bytes: 3028
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define VI vector<int>
#define PII pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x){return mrand()%x;}
clock_t ac; double TLE(){return (double)(clock()-ac)/CLOCKS_PER_SEC;}
void DBG() {cerr << "]" << endl;}
template<class H, class... T> void DBG(H h, T... t) {
cerr << to_string(h);
if(sizeof...(t)) cerr << ", ";
DBG(t...);}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

int main(){
 ios::sync_with_stdio(0);
 cin.tie(0);
 int n,m;
 cin>>n>>m;
 ll ans = (n*(n-1))/2+(m*(m-1))/2;
 cout<<ans<<"\n";
}




Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define endl "\n"



signed main()
{
    FAST;
    int t;
    t=1;
    while(t--)
    {
        int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
        int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
        int left=0,up=0,down=0,start=0,end=0,r=0,q=0,total=0;
        int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
        int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
        
        cin>>n>>k;
        int a[n];
        for(i=0;i<n;i++)
        {
            cin>>a[i];
        }
        
        sort(a,a+n);
        
        for(i=0;i<k;i++)
        {
            sum+=a[i];
        }
        
        cout<<sum<<endl;
        
        
        
        
    }
        
    
    
    
    
}

Measured memory_bytes: 3560
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <climits>
#include <utility>
#include <deque>
#include <list>
#include <stdexcept>
//#include <boost/graph/adjacency_list.hpp>
using namespace std;

int main()
{
	cout << fixed << setprecision(6);
	int n;
	cin >> n;
	vector<int> pls(n);
	for (auto& p : pls) cin >> p;
	
	int decCount = 0;
	for (int i = 0; i < n; ++i) {
		if (pls[i] != i + 1)++decCount;
	}

	cout << (decCount > 2 ? "NO" : "YES") << endl;
	
	return 0;
}

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

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

    int K, T;
    cin >> K >> T;
    vector<int> a(T);
    ll sum = 0;
    REP(i, T) {
        cin >> a[i];
        sum += a[i];
    }
    ll ans = 0;
    REP(i, T) ans = max(ans, a[i] - (sum - a[i]) - 1);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
using namespace std;
typedef long long ll;
const int maxn = 10005;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "w", stdout);
#endif
string s;
cin>>s;
int year = (s[0]-'0')*1000+(s[1]-'0')*100+(s[2]-'0')*10+s[3]-'0';
int mon = (s[5]-'0')*10+s[6]-'0';
int day = (s[8]-'0')*10+s[9]-'0';
bool f = true;
if (year>2019){
  f = false;
} else if(year==2019){
  if(mon>4)f=false;
  else if(mon==4){
    if(day>30)f=false;
  }
}
if(f)cout<<"Heisei"<<endl;
else cout<<"TBD"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 105
#define INF (1e8)
struct edge{int from,to,cost;};

int n,m;
int si,ti,H;

vector<edge> E;
int d[MAX_N];
int prev[MAX_N];
int flg[MAX_N];
int G[MAX_N][MAX_N];
bool er[MAX_N];

void init();
void input();


bool check(edge e){
  if(d[e.from]<=0)return false;
  int C=min(H,d[e.from]+e.cost);

  if(C==d[e.to]){
    prev[e.to]=e.from;
  }
  if(C<=d[e.to]||C<=0)return false;
  d[e.to]=C;
  prev[e.to]=e.from;

  if(er[e.to])d[e.to]=H;
  
  int pos=e.from;
  map<int,bool> visited;
  vector<int> V;
  while(1){
    if(pos==-1)break;
    if(visited[pos])break;
    V.push_back(pos);
    visited[pos]=true;
    pos=prev[pos];
  }
  if(pos==-1||pos!=e.from)return true;
  reverse(V.begin(),V.end());

  int sum=0,size=V.size(),maxm=-INF;
  map<int,int> t;
  for(int i=0;i<size;i++){
    int p=V[i],q=V[(i+1)%size];
    sum=min(H,sum+G[p][q]);
    t[q]=sum;
    maxm=max(maxm,sum);
  }
  for(int i=0;i<size;i++){
    int p=V[i];
    if(t[p]==maxm)d[p]=H;    
  }
  return true;
}

void solve(){
  bool update=true;
  while(update){
    update=false;
    for(int i=0;i<(int)E.size();i++){
      if( check(E[i]) )update=true;
    }
  }
}

int main(){
  int Tc=1;
  while(1){
    cin>>n>>m;
    if(n==0&&m==0)break;
    init();
    input();
    solve();

    cout<<"Case "<<Tc++<<": ";
    if(d[ti]<=0)cout<<"GAME OVER"<<endl;
    else cout<<d[ti]<<endl;
  }
  return 0;
}



void init(){
  E.clear();
  for(int i=0;i<MAX_N;i++){
    d[i]=-INF;
    er[i]=false;
    flg[i]=0;
    prev[i]=-1;
    for(int j=0;j<MAX_N;j++)G[i][j]=-INF;
  }
}

void input(){
 
  for(int i=0;i<m;i++){
    edge e;
    cin>>e.from>>e.to>>e.cost;
    if(e.from==e.to){
      er[e.to]=true;
      continue;
    }
    G[e.from][e.to]=max(G[e.from][e.to],e.cost);
  }
  cin>>si>>ti>>H;
  d[si]=H;
  er[ti]=false;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      if(G[i][j]!=-INF&&i!=ti)
        E.push_back((edge){i,j,G[i][j]});
}

Measured memory_bytes: 1292
import Control.Monad
import Control.Monad.ST
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Array
import Data.Array.ST

main = do
    [n,w]<-map read.words<$>getLine::IO [Int]
    wvs<-replicateM n $ unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[[Int]]
    print $ f n w wvs

f n w wvs = runST $ do
    dp <- newArray ((0,0),(n,w)) 0 :: ST s (STUArray s (Int,Int) Int)
    forM_ [(i,wi,vi,j)|(i,[wi,vi])<-zip [1..] wvs,j<-[0..w]] $ \(i,wi,vi,j) ->
        if j<wi then
            writeArray dp (i,j) =<< readArray dp (i-1,j)
        else 
            writeArray dp (i,j) =<< max <$> readArray dp (i-1,j) <*> ((+vi)<$>readArray dp (i-1,j-wi))
    readArray dp (n,w)


Measured memory_bytes: 80380
#include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;
 
#define all(v) v.begin(),v.end()
#define test() int t;cin>>t;while(t--) 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ff first
#define ss second
const ll mod = (ll)1e9 + 7;
const ll INF = -(ll)1e10;

int main()
{
    int n;
    cin>>n;
    vi a(n), b(n), cnta(n+1), cntb(n+1);
    for(int i = 0; i<n; i++)
    {
        cin>>a[i];
        cnta[a[i]]++;
    }
    for(int i =0; i<n; i++)
    {
        cin>>b[n-i-1];
        cntb[b[n-i-1]]++;
    }
    int start = -1, end = n, idx = 0;
    while(true)
    {
        while(idx<n && a[idx]!=b[idx])idx++;
        start = idx;
        while(idx<n && a[idx]==b[idx])idx++;
        end = idx;
        break;        
    }
    if(start == n)
    {
        cout<<"Yes"<<endl;
        for(int x : b)cout<<x<<" ";
        cout<<endl;
        return(0);
    }
    if(cnta[a[start]]>n-cntb[b[start]])
    {
        cout<<"No"<<endl;
        return(0);
    }
    int curr = start;
    for(int  i = 0; i<n; i++)
    {
        if(b[i]!=b[curr] && a[i]!=a[start])
        {
            swap(b[i], b[curr++]);
            if(curr==end)break;
        }
    }
    cout<<"Yes"<<endl;
    for( int x : b)cout<<x<<" ";
    cout<<endl;
}


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

int main() {
	int N, H[100010], dp[100010];
	cin >> N;
    for (int i = 0; i < N; ++i){
        cin >> H[i];
    }

    dp[0] = 0;
    dp[1] = std::abs(H[1] - H[0]);
    for (int i = 2; i < N; ++i){
        dp[i] = min(dp[i-1] + std::abs(H[i] - H[i-1]), dp[i-2] + std::abs(H[i] - H[i-2]) );
    }

    cout <<  dp[N-1] << endl;
	return 0;
}

Measured memory_bytes: 4412
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int A[] = new int[N];
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		System.out.println((int)Math.ceil((double)(N - 1) / (double)(K - 1)));
	}
}


Measured memory_bytes: 48824
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}//standard output
        static void myerr(Object t){System.err.println(t);}//standard error
        static String getStr(){return sc.next();}
        static int getInt(){return Integer.parseInt(getStr());}
        static long getLong(){return Long.parseLong(getStr());}
        static boolean hasNext(){return sc.hasNext();}
        static char[] mySplit(String str){return str.toCharArray();}
        public static void main(String[] args){
          long a = getLong();
          long b = getLong();
          long c = getLong();
          if(c - a - b < 0){
            myout("No");
            return;
          }
          if(4 * a * b < (c - a - b) * (c - a - b)){
            myout("Yes");
          }else{
            myout("No");
          }
        }
        //Method addition frame start

        //Method addition frame end
}


Measured memory_bytes: 21844
A = [0,0,0,0]
for i in range(3):
  a,b = map(int,input().split())
  A[a - 1] += 1
  A[b - 1] += 1

if all([A[i] < 3 for i in range(4)]):
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3060
// Educational DP - ATCoder - A - Frog 1
// A. Bacca
#include <iostream>
#include <vector>
using namespace std;

int n;
vector <int> heights;
vector <int> dp_step;

void Recibir() {
	cin >> n;
	dp_step.assign(n, -1);
	heights.resize(n);
	for (int i=0; i<n; i++) cin >> heights[i];
}

int Cost(int x) {
	// No saved data
	if (dp_step[x] != -1) return dp_step[x];
	// Last item
	else if (x == n-1) return dp_step[x] = 0;
	// Penultimate item
	else if (x == n-2) return dp_step[x] = Cost(x+1) + abs(heights[x] - heights[x+1]);
	// Check both
	else return dp_step[x] = min(Cost(x+1) + abs(heights[x] - heights[x+1]), Cost(x+2) + abs(heights[x] - heights[x+2]));
}

int main() {
	Recibir();
	cout << Cost(0);
	return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
int main(){
	vector<ll> mass_i;
	vector<ll> mass_j;
	ll N,best_score;
	cin >> N;
	for (ll i = 1; i <= N;i++){
		if(i > N/i)
			break;
		if(N%i == 0){
			mass_i.push_back(i);
			mass_j.push_back(N / i);
		}
	}
	for (ll i = 0; i < mass_i.size(); i++)
	{
		if (best_score > mass_i[i] + mass_j[i] - 2 || best_score == 0)
		{
			best_score = mass_i[i] + mass_j[i] - 2;
		}
	}
	cout << best_score;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;

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

ull lcm(ull a, ull b) {
    ull g = gcd(a, b);
    return a / g * b;
}

int main(){
    int N, i;
    ull T, ans=1;

    cin >> N;

    for (i=0; i<N; i++) {
        cin >> T;
        ans = lcm(ans, T);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
function Main(input) {
  var N = input.trim().length;
  var count = 0;
  var color = 0;
  
  for(i=0;i<N;i++){
    if (parseInt(input.charAt(i)) == color) count++;
    color = (color + 1)%2;
  }
  console.log(Math.min(count,N-count));
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int id[40];
int G[40][40];
string name[40];
int B[40];
vector<string> D[40];
int N;
int ans;
map<string, int> m;

void f(int n, ll mask, int sum) {
	if(n == N) {
		/*for(int i = 0; i < N; i++) {
			if(mask >> i & 1) cout << name[i] << " ";
		}
		cout << endl;*/
		ans = max(ans, sum);
		return;
	}

	int tsum = 0;
	for(int i = n; i < N; i++) {
		tsum += B[id[i]];
	}
	if(sum + tsum <= ans) return;

	bool canUse = true;
	for(int i = 0; i < N; i++) {
		if((mask >> id[i] & 1) && G[m[name[id[n]]]][m[name[id[i]]]]) {
			canUse = false;
			break;
		}
	}

	if(canUse) {
		f(n + 1, mask | (1LL << id[n]), sum + B[id[n]]);
	}

	f(n + 1, mask, sum);
}

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

	while(cin >> N, N) {
		m.clear();
		for(int i = 0; i < N; i++) {
			cin >> name[i] >> B[i];
			m[name[i]] = i;
			int C;
			cin >> C;
			D[i].assign(C, "");
			for(int j = 0; j < C; j++) {
				cin >> D[i][j];
			}
		}

		int myPow = B[0];
		B[0] = 1e9;

		typedef pair<int, int> P;
		vector<P> p;
		for(int i = 0; i < N; i++) {
			p.push_back({ B[i], i });
		}
		sort(p.begin(), p.end());
		reverse(p.begin(), p.end());

		B[0] = myPow;
		for(int i = 0; i < N; i++) {
			id[i] = p[i].second;
		}

		memset(G, 0, sizeof G);
		for(int i = 0; i < N; i++) {
			for(auto s : D[i]) {
				G[m[name[i]]][m[s]] = G[m[s]][m[name[i]]] = 1;
			}
		}

		ans = 0;
		f(1, 1, B[0]);

		cout << ans << endl;
	}
}

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

using namespace std;
typedef long long ll;
#define INF 1e9+1
#define rep(i,n) for(int i=0;i<n;i++)
int N,W;
int w[101],v[101];
int dp[101][100100];
int main(){
    cin >> N >> W;
    for(int i=1;i<=N;i++){
        cin >> w[i] >> v[i];
    }
    rep(i,N){
        rep(j,100001){
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    for(int i=0;i<N;i++){
        for(int j=0;j<=100000;j++){
            dp[i+1][j] = dp[i][j];
            if(j>=v[i+1]){
                dp[i+1][j] = min(dp[i][j],dp[i][j-v[i+1]]+w[i+1]);
            }
        }
    }
    int min = INF;
    int i;
    int temp = 0;
    for(i=0;i<=100000;i++){
        if(dp[N][i]<=W){
            temp = i;
        }
    }
    cout << temp << endl;
    
    
    return 0;

}

Measured memory_bytes: 39808
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
using ll = long long;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
int main(){
  ll n;
  cin >> n;
  ll a[n];
  ll sum=0;
  rep(i,n){
    cin >> a[i];
    sum += a[i];
  }
  sort(a,a+n);
  sum -= a[n-1]/2;
  cout << sum;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    cin>>N;
    vi a(N);
    vi ans(100100,0);    
    rep(i,N) cin>>a[i];
    rep(i,N) {
        ans[a[i]]++;
        ans[a[i]+1]++;
        if(a[i]!=0) ans[a[i]-1]++;
    }
    sort(ans.begin(),ans.end(),greater<int>());
    cout<<ans[0]<<endl;
}

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

int main() {
  int n,a,b;
  string s;
  cin >> n >> a >> b >> s;
  int cnt1=0,cnt2=0;
  for ( int i=0; i<n; i++ ) {
    if ( s[i]=='a' ) {
      if ( cnt1+cnt2<a+b ) {
        cout << "Yes" << '\n';
        cnt1++;
      } else {
        cout << "No" << '\n';
      }
    }
    else if ( s[i]=='b' ) {
      if ( cnt2<b&&cnt1+cnt2<a+b ) {
        cout << "Yes" << '\n';
        cnt2++;
      } else {
        cout << "No" << '\n';
      } 
    }
    else {
      cout << "No" << '\n';
    } 
  }
  return 0; 
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;
int H, W;
int c[10][10];
int dist[10][10];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> H >> W;
    rep(y, 10)
    {
        rep(x, 10)
        {
            cin >> c[y][x];
        }
    }
    ll res = 0;
    // warshall-floyd法でi->jの最小値を求める
    rep(k, 10) {
        rep(i, 10) {
            rep(j, 10) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }


    rep(y, H)
    {
        rep(x, W)
        {
            int a;
            cin >> a;
            if (a >= 0) {
                res += c[a][1];
            }
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
s[50],j,p,q;main(i){for(;j=i=atoi(gets(s));printf("%d\n",i)){for(;i;s[j-i--]=strlen(gets(s+j)));for(;j;)for(p=i++,q=j=117933;q>0;j/=9)for(q=j%9;q>1;)q-=s[p++];}}

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

int N;
vector<int> a;

void solve() {
    vector<int> res;
    for (int i = 0; i < N; ++i) {
        int pivot = -1;
        for (int j = (int)a.size()-1; j >= 0; --j) {
            if (a[j] == j) {
                pivot = j;
                break;
            }
        }
        if (pivot == -1) {
            cout << -1 << endl;
            return;
        }

        res.push_back(pivot + 1);
        a.erase(a.begin() + pivot);
    }
    reverse(res.begin(), res.end());
    for (auto v : res) cout << v << endl;
}

int main() {
    cin >> N;
    a.resize(N);
    for (int i = 0; i < N; ++i) cin >> a[i] , --a[i];
    solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int i,j,n,m,rez,r;
string s[200],t[200];
int main()
{
    std::cin.sync_with_stdio(false);
    std::cin.tie(0);
    cin >> n;
    i=0;
    while (i<n)
    {
        cin >> s[i];
        i++;
    }
    cin >> m;
    i=0;
    while (i<m)
    {
        cin >> t[i];
        i++;
    }
    sort(s,s+n);
    sort(t,t+m);
    i=0;
    rez=0;
    while (i<n)
    {
        r=1;
        j=0;
        while (j<m)
        {
            if (t[j]==s[i])
            {
                r--;
            }
            j++;
        }
        while (s[i+1]==s[i])
        {
            r++;
            i++;
        }
        rez=max(rez,r);
        i++;
    }
    cout << rez;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 1000000000 //1E+9
#define mod 1000000007
using namespace std;

int main(){
	set<int> prime; prime.insert(2);
	for(int i=3;i<=100000;i+=2){
		int flag=1;
		for(auto itr=prime.begin();itr!=prime.end();itr++)if(i%(*itr)==0){flag=0; break;}
		if(flag)prime.insert(i);
	}
	set<int> similar;
	for(auto itr=prime.begin();itr!=prime.end();itr++){
		if(prime.count((*itr+1)/2))similar.insert(*itr);
	}


	vector<int> cumulated(100000,0);
	for(int i=3;i<100000;i++){
		if(similar.count(i))cumulated[i]=cumulated[i-1]+1;
		else cumulated[i]=cumulated[i-1];
	}

	int q;cin>>q;
	int l[q],r[q];for(int i=0;i<q;i++)cin>>l[i]>>r[i];
	for(int i=0;i<q;i++)cout<<cumulated[r[i]]-cumulated[l[i]-1]<<endl;
}



Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define int long long
int neet(int a,int b){
if(a%b==0)return b;
else return neet(b,a%b);
}
signed main()
{
    int A,B,C,D;
    cin >> A>>B>>C>>D;
    A=A-1;
        int i=0,na=A,nb=B;
       nb-=B/C+B/D;
       nb+=B/(C*D/neet(C,D));

       na-=A/C+A/D;
       na+=A/(C*D/neet(C,D));
   cout <<nb-na <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <string>
#include <map>
using namespace std;
#define REP(i, a, n) for (int i = ((int)a); i < ((int)n); i++)
#define lli long long int

#define MAX 100000000
//#define DEBUG

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

int main()
{
#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
#else
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
#endif
    int a,b;
    cin>>a>>b;
    if(a==b){
        cout<<2*a<<endl;
    }else{
        cout<<2*max(a,b)-1<<endl;
    }
    return 0;
}
/* 注意すべき点
グローバル以外の配列は初期化すべし
*/

Measured memory_bytes: 256
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

def main():
    n = int(input())
    alis = list(map(int, input().split()))
    a = alis[0] ^ alis[1]
    for i in range(2, len(alis)):
        a = a^alis[i]
    ans = []
    for num in alis:
        ans.append(str(a^num))
    print(' '.join(ans))

    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 102848
#include<set>
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    set <int> s;
    while(n--)
    {
        int x;
        cin>>x;
        if(s.find(x)!=s.end()) s.erase(x);
        else s.insert(x);
    }
    cout<<s.size();
    return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e15;

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

int main(){
    ll N, A, B, K;
    cin >> N >> A >> B >> K;
    vector<P> vec;
    rep(i, N+1){
        if((A*i)%B == K % B && A*i <= K && K <= A*i + B*N){
            vec.push_back(P(i, (K-A*i)/B));
            break;
        }
    }
    if(vec.size() == 0) cout << 0 << endl, exit(0);
    ll s = vec[0].first;
    ll t = vec[0].second;
    ll g = gcd(A, B);
    ll stepA = B/g, stepB = A/g;
    while(s + stepA <= N && t - stepB >= 0){
        s += stepA;
        t -= stepB;
        vec.push_back(P(s, t));
    }
    ll n = N;
    ll inv[n+1];
    rep2(i, 1, n+1){
        inv[i] = 1;
        ll e[30];
        e[0] = i;
        rep2(j, 1, 30){
            e[j] = (e[j-1]*e[j-1]) % MOD2;
        }
        ll k = MOD2-2;
        int count = 0;
        while(k > 0){
            if(k % 2 == 1){
                inv[i] *= e[count];
                inv[i] %= MOD2;
            }
            k /= 2;
            count++;
        }
    }
    ll fac[N+1], perm[N+1];
    fac[0] = 1, perm[0] = 1;
    rep(i, N){
        fac[i+1] = (fac[i]*inv[i+1])%MOD2;
        perm[i+1] = (perm[i]*(N-i))%MOD2;
    }
    ll ans = 0;
    rep(i, vec.size()){
        ll s = vec[i].first, t = vec[i].second;
        ll tmp = 1;
        tmp *= perm[s], tmp %= MOD2;
        tmp *= fac[s], tmp %= MOD2;
        tmp *= perm[t], tmp %= MOD2;
        tmp *= fac[t], tmp %= MOD2;
        ans += tmp, ans %= MOD2;
    }
    cout << ans << endl;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; -i)
#define INF (1 << 30)
#define MOD 1000000007

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

int main() {
	int a, b;
	while(scanf("%d %d", &a, &b), a || b) {
		int ans = 0;
		for(int i = 1; i < a + 1; ++i) {
			for(int j = i + 1; j < a + 1; ++j) {
				for(int k = j + 1; k < a + 1; ++k) {
					if(i + j + k == b) ++ans;
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3176
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  long int sum=0;
  for(int i=1;i<n;i++){
  sum+=n/i;
  if(n%i==0)sum--;
  
  
  }
  cout<<sum;
  
  
  
  
  
  
  return 0;}


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

int main() {
    int n, s[110];
    int sum = 0, mini = 1000;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        sum += s[i];
        if (s[i] % 10 != 0) mini = min(mini, s[i]);
    }

    if (sum % 10 == 0) {
        if (mini == 1000) cout << 0 << endl;
        else cout << sum - mini << endl;
    }
    else  cout << sum << endl;
}

Measured memory_bytes: 3592
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int,input().split()))
acum = [0]*(n+1)
for i in range(n):
  acum[i+1] = acum[i] + A[i]
C = collections.Counter()
for i in range(n+1):
  ans += C[acum[i]]
  C[acum[i]] += 1
print(ans)


Measured memory_bytes: 41580
#include <iostream>
#include <string.h>
using namespace std;

int main () {
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != s[s.size() - i - 1]) cnt++; 
  }
  cout << cnt / 2 << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,a) for(int i=lst[a];i;i=nxt[i])
using namespace std;

typedef long long ll;

int read() {
	char ch;
	for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
	int x=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

const int N=1e5+5;

int t[N<<1],nxt[N<<1],lst[N],l;
void add(int x,int y) {t[++l]=y;nxt[l]=lst[x];lst[x]=l;}

int n,m,a[N],b[N],fa[N],ord[N];
bool vis[N];
ll f[N],sum[N];

vector<int> to[N];

int get(int x) {return fa[x]?fa[x]=get(fa[x]):x;}

bool cmp(int x,int y) {return a[x]<a[y];}

void merge(int x,int y) {
	int a=get(x),b=get(y);
	if (a==b) return;
	fa[b]=a;to[x].push_back(b);
}

void dfs(int x) {
	if (to[x].empty()) {
		sum[x]=b[x];f[x]=a[x];
		return;
	}
	sum[x]=b[x];
	for(int y:to[x]) dfs(y),sum[x]+=sum[y];
	f[x]=1e18;
	for(int y:to[x]) f[x]=min(f[x],max(f[y],a[x]-sum[y]));
}

int main() {
	n=read();m=read();
	fo(i,1,n) a[i]=read(),b[i]=read(),a[i]=max(0,a[i]-b[i]);
	fo(i,1,m) {
		int x=read(),y=read();
		add(x,y);add(y,x);
	}
	fo(i,1,n) ord[i]=i;
	sort(ord+1,ord+n+1,cmp);
	fo(i,1,n) {
		int x=ord[i];vis[x]=1;
		rep(j,x) {
			int y=t[j];
			if (!vis[y]) continue;
			merge(x,y);
		}
	}
	dfs(ord[n]);
	printf("%lld\n",f[ord[n]]+sum[ord[n]]);
	return 0;
}

Measured memory_bytes: 14464
n,m = map(int,input().split())
dp = [0]*n

for i in range(m):
    dp[int(input())-1] = 10**12
    
if dp[0] == 10**12:
    dp[0] = 0
else:
    dp[0] = 1

if n == 1:
    print(dp[0])
else:
    if dp[1] == 10**12:
        dp[1] = 0
    else:
        dp[1] = 1+ dp[0]

    mod = 1000000007

    for i in range(2,n):
        if dp[i] == 10**12:
            dp[i] = 0
        else:
            dp[i] = dp[i-1] + dp[i-2]
            dp[i] %= mod
    print(dp[-1])

Measured memory_bytes: 6900
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/

int n, k, a[305];
int dp[305][305][305];
signed main() {
	cin >> n >> k;
	REP(i, n + 1)cin >> a[i];
	rep(i, 305)rep(j, 305)rep(k, 305)dp[i][j][k] = inf;
	dp[1][0][0] = 0;
	REP(i, n + 1) {
		rep(j, k + 1) {
			rep(k, i) {
				if (a[k] < a[i]) {
					chmin(dp[i + 1][j][i], dp[i][j][k] + a[i] - a[k]);
				}
				else {
					chmin(dp[i + 1][j][i], dp[i][j][k]);
				}
				chmin(dp[i + 1][j + 1][k], dp[i][j][k]);
			}
		}
	}
	int ans = inf;
	rep(i, k + 1)rep(j, 305)chmin(ans, dp[n + 1][i][j]);
	cout << ans << endl;
}


Measured memory_bytes: 221952
#include<stdio.h>
int main()
{
    int i,n,a,max,min;
    scanf("%d",&n);
    scanf("%d",&a);
   long long sum=a;
    max=a;
    min=a;
    for(i=1;i<n;i++)
    {
    scanf("%d",&a);

        sum=sum+a;
        if(a>max)
        max=a;
        if(a<min)
        min=a;
    }
    printf("%d %d %lld\n",min,max,sum);
    return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define pii pair< int,int>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define ll long long int
#define mod 1000000007
#define mxn 2000010
#define sqr 320
ll arr[mxn],m,n;
vector<pair<ll,ll> > vr,vb;
ll f(double mo,ll c)
{
ll r1=0,r2=0,i;
for(i=0;i<n;i++)
{
  double op=vr[i].S-mo*vr[i].F-c;
  if(op<0)
    r1++;
  if(op>0)
    r2++;
}
for(i=0;i<m;i++)
{
  double op=vb[i].S-mo*vb[i].F-c;
  if(op<0)
    r2++;
  if(op>0)
    r1++;
}
return -min(r1,r2);
}
int main() {
    // ios::sync_with_stdio(0);
    // cin.tie(0);
    // cout.tie(0);
      ll x,y;
      cin>>x>>y;
    ll op=0;
    while(x<=y)
    {
      x*=2;
      op++;
    }
    cout<<op;
     return 0;
    }

Measured memory_bytes: 256
//https://atcoder.jp/contests/dp/tasks/dp_h

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

int main()
{
    int n,m;
    cin >> n >> m;
    string s[n];
    for(int i=0 ; i<n; i++)
        cin >> s[i];
    ll M = 1e9+7;
    ll dp[n][m];
    for(int i=0 ; i<n ; i++)
    {
        for(int j=0 ; j<m ; j++)
        {
            if(s[i][j] == '#')
            {
                dp[i][j] = 0;
                continue;
            }
            if(i==0 && j==0)
                dp[i][j] = 1;
            else if(i==0)
                dp[i][j] = dp[i][j-1];
            else if(j==0)
                dp[i][j] = dp[i-1][j];
            else
                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%M;
        }
    }
    /*for(int i=0 ; i<n ; i++)
    {
      for(int j=0 ; j<m ; j++)
            cout << dp[i][j] << " ";
      cout << "\n";
    }*/
    cout << dp[n-1][m-1];
    return 0;
}


Measured memory_bytes: 13276
n, k = map(int, input().split())
s = input()

c = 1
l = []
l += [0,0] if (s[0] == '0') else [0]

for i in range(1, n):
    if s[i-1] != s[i]:
        l += [c+l[-1]]; c = 1;
    else:
        c +=1

l += [c+l[-1]]
if s[-1] == '0':
   l += [l[-1]]

ll = len(l)
pl = 2 * k + 1

if ll <= pl:
    print(n)
else: 
    m = 0
    for i in range(0, ll-pl+1, 2):
        t = l[pl+i]-l[i]; m = t if (t > m) else m
    print(m)


Measured memory_bytes: 7164
use std::cmp::max;
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Input {
    n: usize,
    abc: Vec<Vec<i32>>,
}

fn read_input(cin_lock: &mut StdinLock) -> Input {
    let n = next_token(cin_lock);
    let abc = (0..n)
        .map(|_| (0..3).map(|_| next_token(cin_lock)).collect())
        .collect();
    Input { n, abc }
}

fn solve(input: Input) {
    let mut dp = vec![vec![0; 3]; input.n + 1];

    for i in 0..input.n {
        for j in 0..3 {
            dp[i + 1][j] = input.abc[i]
                .iter()
                .enumerate()
                .fold(dp[i + 1][j], |acc, (k, v)| {
                    if j == k {
                        acc
                    } else {
                        max(acc, dp[i][k] + v)
                    }
                });
        }
    }
    println!("{}", dp[input.n].iter().fold(0, |acc, x| max(acc, *x)));
}

fn next_token<T: FromStr>(cin_lock: &mut StdinLock) -> T {
    cin_lock
        .by_ref()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>()
        .parse::<T>()
        .ok()
        .unwrap()
}

fn main() {
    let cin = stdin();
    let mut cin_lock = cin.lock();
    let input = read_input(&mut cin_lock);
    solve(input);
}


Measured memory_bytes: 12808
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys


a = int(input())
s = input()
if a >= 3200:
    print(s)
else:
    print('red')


Measured memory_bytes: 6992
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;

int main(){
    int n; cin >> n;
   rep(i, 50000){
       if((int)(i * 1.08) == n){
           cout << i << endl;
           return 0;
       }
   }
    cout << ":(" << endl;
}

Measured memory_bytes: 256
import math
N = int(input())
x = math.ceil(math.sqrt(N))
ans = [0]*N

def f(x,y,z):
    return x**2+y**2+z**2+x*y+y*z+z*x

for i in range(1,x):
    for j in range(i,x):
        for k in range(j,x):
            s = f(i,j,k)
            t = len(set([i,j,k]))
            if N >= s:
                if t == 3:
                    ans[s-1] += 6
                elif t == 2:
                    ans[s-1] += 3
                elif t ==1:
                    ans[s-1] += 1
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 9140
#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 = R[1] - R[0];
    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: 3852
#include <bits/stdc++.h>

#include <deque>
#include <vector>

using namespace std;
using ll = long long;

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

    deque<int> a;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }

    deque<int> b;
    for (int i = 0; i < n; i++) {
        if ((n - i) % 2 == 1) {
            b.push_back(a.front());
            a.pop_front();
        } else {
            b.push_front(a.front());
            a.pop_front();
        }
    }

    while (!b.empty()) {
        cout << b.back() << " ";
        b.pop_back();
    }

    return 0;
}


Measured memory_bytes: 4460
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll>adj[100002];
ll visit[100002];

ll dp(ll val)
{
    ll p;
    if(visit[val]!=-1)return visit[val];
    p=0;
    for(ll j=0; j<adj[val].size(); j++)
    {
        p=max(p,1+dp(adj[val][j]));
    }
    return visit[val]=p;
}

int main()
{
    ll n,m,i,a,b;
    scanf("%lld %lld",&n,&m);
    while(m--)
    {
        scanf("%lld %lld",&a,&b);
        adj[a].push_back(b);
    }
    memset(visit,-1,sizeof(visit));
    m=-1;
    for(i=1; i<=n; i++)
    {
        if(visit[i]==-1)
        {
            m=max(m,dp(i));
        }
    }
    printf("%lld\n",m);
    return 0;
}


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

#define MAX_N 50
#define MAX_DAY 30

int solve(const int &n, const bool isFreeDay[MAX_DAY + 1][MAX_N]) { // O(MAX_DAY * n^2)
  const ll gathered = (1LL << n) - 1;

  // dp[i][j] := Set of maps available for person j on day i
  ll dp[MAX_DAY + 1][MAX_N] = {};
  for (int j = 0; j < n; j++) dp[0][j] |= 1LL << j;

  for (int i = 1; i <= MAX_DAY; i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j] |= dp[i - 1][j];
      if (isFreeDay[i][j]) {
        for (int k = 0; k < n; k++) {
          if (isFreeDay[i][k]) dp[i][j] |= dp[i - 1][k];
        }
      }

      if (dp[i][j] == gathered) return i;
    }
  }
  return -1;
}

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;
    // isFreeDay[i][j] := whether if day i is free for person j
    bool isFreeDay[MAX_DAY + 1][MAX_N] = {};
    for (int i = 0; i < n; i++) {
      int f;
      cin >> f;
      while (f--) {
        int d;
        cin >> d;
        isFreeDay[d][i] = true;
      }
    }
    cout << solve(n, isFreeDay) << endl;
  }
}



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

int main() {
    int D;
    cin >> D;
    switch (D) {
        case 22:
            cout << "Christmas Eve Eve Eve\n";
            break;
        case 23:
            cout << "Christmas Eve Eve\n";
            break;
        case 24:
            cout << "Christmas Eve\n";
            break;
        case 25:
            cout << "Christmas";
            break;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n,m;
  cin>>n>>m;
  ll a[max(n,m)+1];
  a[0]=1;
  rep(i,0,max(n,m)){
    a[i+1]=a[i]*(i+1)%mod;
  }
  if(n==m){
    cout<<a[n]*a[m]%mod*2%mod<<endl;
  }
  else if(n-m==1 || m-n==1){
    cout<<a[n]*a[m]%mod<<endl;
  }
  else{
    cout<<0<<endl;
  }
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(int argc, char* argv[])
{
  int a, b, c, w;
  scanf("%d %d %d", &a, &b, &c);

  if(a > b){
    w = a;
    a = b;
    b = w;
  }
  if(b > c){
    w = b;
    b = c;
    c = w;
  }
  if(a > b){
    w = a;
    a = b;
    b = w;
  }
  
  printf("%d %d %d\n", a, b, c);

  return(0);
}

Measured memory_bytes: 596
#include <stdio.h>

int main()
{
	int n, k, i;
	int cnt = 0;
	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++) {
		int h = 0;
		scanf("%d", &h);
		if (h >= k)
			cnt++;
	}
	printf("%d", cnt);
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
    int t,a,b,c,i;
    scanf("%d",&t);
    for(i=1;i<=t;i++)
    {
        scanf("%d %d %d",&a,&b,&c);
        if((a*a+b*b==c*c)||(b*b+c*c==a*a)||(a*a+c*c==b*b))
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    return 0;
}

Measured memory_bytes: 580
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil
def main():
    n, k = map(int, input().split())
    if k == 1:
        print(0)
        sys.exit()
    r1 = n % k
    r2 = abs(r1 - k)
    r = min(r1, r2)
    print(r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9100
#include <cstdio>
#include <algorithm>
#define maxn 200010
int a[maxn],head[maxn],tot,n,d[maxn],ans,mx[maxn];
using namespace std;
struct node{
	int to,next;
}e[maxn<<1];
void add_edge(int u,int v){
	tot++,e[tot].to=v,e[tot].next=head[u],head[u]=tot;
}
void dfs(int u,int fa){
	int b,v,save,flag,l,r,mid;;
	for(b=head[u];b;b=e[b].next){
		v=e[b].to;
		if(v==fa)continue;
		save=ans,flag=0;
		if(d[ans]<a[v])d[++ans]=a[v];
		else{
			l=0,r=ans;
			while(l+1<r){
				mid=(l+r)/2;
				if(d[mid]<a[v])l=mid;
				else r=mid;
			}
			flag=d[r],d[r]=a[v];
		}
		mx[v]=ans;
		dfs(v,u);
		ans=save;
		if(flag)d[r]=flag;
	}
}
void init(){
	int i,u,v;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	for(i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		add_edge(u,v),add_edge(v,u);
	}
}
int main(){
	init();
	ans=1,d[1]=a[1],mx[1]=1;
	dfs(1,0);
	for(int i=1;i<=n;i++)printf("%d\n",mx[i]);
	return 0;
}

Measured memory_bytes: 21556
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String args[]) throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        double a= Double.parseDouble(reader.readLine());
        System.out.printf("%6f %6f",a*a*Math.PI,a*2*Math.PI);
    }
}

Measured memory_bytes: 24624
#include<iostream>
using namespace std;
int main(){
	int a,b,k,i;
	cin>>k>>a>>b;
	for(i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			cout<<"OK";
			return 0;
		}
	}
	cout<<"NG";
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define F first
#define S second
const int N = 106;
pii x[N], y[N];
vector<int> gx[N];
int vy[N], my[N];
bool mat(int a)
{
    for (int b : gx[a]) if (!vy[b]) {
        vy[b] = 1;
        if (my[b] == -1 || mat(my[b])) {
            my[b] = a;
            return 1;
        }
    }
    return 0;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> x[i].F >> x[i].S;
    for (int i = 0; i < n; ++i)
        cin >> y[i].F >> y[i].S;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (x[i].F < y[j].F && x[i].S < y[j].S) {
                gx[i].push_back(j);
            }
        }
    }
    int ans = 0;
    memset(my,-1,sizeof(my));
    for (int i = 0; i < n; ++i) {
        memset(vy,0,sizeof(vy));
        ans += mat(i);
    }
    cout << ans << endl;
}


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

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());

    string S;
    cin >> S;

    bool has01 = true;
    int before_length = S.length();
    while(has01) {
        has01 = false;
        for (int i = 0; i < S.length()-1; i++) {
            if (S[i] != S[i+1]) {
                S.erase(S.begin() + i + 1);
                S.erase(S.begin() + i);
                if (S.length() > 1) {
                    has01 = true;
                }
                break;
            }

        }
    }
    cout << before_length - S.length() << endl;

}


Measured memory_bytes: 512
N,M=map(int, input().split())
inlist = [tuple([int(st) for st in input().split()]) for i in range(M)]
inlist.sort()
res=0
minright=100000000000
for fr, to in inlist:
    if to < minright: minright = to
    if minright <= fr:
        res += 1
        minright = to
print(res+1)


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

long long n, i, a[7], b, c;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(NULL);

	for (i=1; i<=3; i++) {
		cin >> a[i];
		if (a[i]%2==0) {
			cout << 0;
			return 0;
		}
	}
	sort(a+1, a+4);
	cout << a[1]*a[2];
	return 0;

}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }

  bool a;
  for(int i=0;i<N;i++){
    if(A.at(i)%2!=0){
      continue;
    }
    else{
      if(A.at(i)%3==0 || A.at(i)%5==0){
        a=true;
      }
      else if(A.at(i)%3!=0 && A.at(i)%5!=0){
        a=false;
        break;
      }
    }
  }
  if(a){
    cout << "APPROVED" << endl;
  }
  else{
    cout << "DENIED" << endl;
  }
}

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

int main(){
  long long n,a,b;
  cin >> n >> a >> b;
  
  long long c=a+b;
  long long ans = a*(n/c);
  ans += min(n%c,a);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256