akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;
 
 
int main() {
    int N; cin >> N;
    vector<ll> A(N,0);
    REP(i,N) cin >> A[i];
 
    ll num = 0;
 
    int r = 0;
    ll ans = 0;
    REP(l,N){
        while(r<N){
            if(num+A[r] == (num^A[r])){
                num += A[r];
                r++;
                ans++;
            }else{
                break;
            }
        }
        num -= A[l];
        ans += r-l;
    }
    ans -= N;
    cout << ans << endl;
 
    return 0;
}

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    string s,t; cin>>s>>t;
    ll n=s.size();
    s+=s;
    bool can=false;
    rep(i,s.size()){
        if(s.substr(i,n)==t) can=true;
    }
    cout<<(can?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<long long> a;
    for(int i=0; i<n; ++i){
        long long tmp;
        cin >> tmp;
        a.push(tmp);
    }

    for(int i=0; i<m; ++i){
        long long b=a.top()/2;
        a.pop();
        a.push(b);
    }
    long long ans=0;
    for(int i=0; i<n; ++i){
        ans += a.top();
        a.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
h, w, a, b = map(int, input().split())
for _ in range(b):
  print(''.join(['1' for _ in range(a)] + ['0' for _ in range(w-a)]))
for _ in range(h-b):
  print(''.join(['0' for _ in range(a)] + ['1' for _ in range(w-a)]))


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

typedef struct{
    int num;
    int* array;
}List;

int main(){
    int n;
    int buff;
    int buff_num;
    int matrix[100][100];
    int count=0;
    List* list;


    scanf("%d",&n);
    list=malloc(sizeof(List)*n+1);

    for(int i=1;i<=n;i++){
        scanf("%d%d",&buff,&buff_num);
        (list+buff)->num=buff_num;
        (list+buff)->array=malloc(sizeof(int)*buff_num);
        for(int j=0;j<buff_num;j++){
            scanf("%d",&list[buff].array[j]);
        }
    }

    /*for(int i=1;i<=n;i++){
        printf("%d",list[i].num);
        for(int j=0;j<list[i].num;j++){
            printf(" %d",list[i].array[j]);
        }
        printf("\n");
    }*/

    for(int i=1;i<=n;i++){
        count=0;
        for(int j=1;j<=n;j++){
            if(j==(list+i)->array[count]){
                count++;
                printf("1");
            }
            else{
                printf("0");
            }
            if(j!=n)
                printf(" ");
        }
        printf("\n");
    }

    return 0;

}



Measured memory_bytes: 2112
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

array<array<int, 200>, 200> dp;

int main(){
    string s;
    while(cin >> s, s != "#"){
        string t; cin >> t;
        int a, b, c, d; cin >> a >> b >> c >> d;
        int ans = INF<int>;
        for (int q = 0; q < s.size(); ++q) {
            for (int j = 0; j <= s.size(); ++j) {
                for (int k = 0; k <= t.size(); ++k) {
                    dp[j][k] = INF<int>;
                }
            }
            dp[0][0] = 0;
            for (int j = 0; j <= s.size(); ++j) {
                for (int k = 0; k <= t.size(); ++k) {
                    if(k) dp[j][k] = min(dp[j][k], dp[j][k-1] + a);
                    if(j) dp[j][k] = min(dp[j][k], dp[j-1][k] + b-d*((int)s.size()-q < j));
                    if(k && j) dp[j][k] = min(dp[j][k], dp[j-1][k-1] + c*(s[j-1] != t[k-1]));
                }
            }
            ans = min(ans, dp[s.size()][t.size()]+q*d);
            char c = s.front();
            s = s.substr(1, s.size());
            s += c;
        }
        cout << ans << "\n";
    }
    return 0;
}


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

const int MAX_N = 5e5+10, MAX_Q = 5e5+10;
int N, Q;
int c[MAX_N];
int l[MAX_Q],r[MAX_Q];
vector<int> qry[MAX_N];
vector<int> qid[MAX_N];
int lst[MAX_N];
int dat[MAX_N];
int ans[MAX_Q];

void add(int i, int v)
{
	while(i<=N){
		dat[i]+=v;
		i+=i&-i;
	}
}

int sum(int i)
{
	int res = 0;
	while(i>0){
		res+=dat[i];
		i-=i&-i;
	}
	return res;
}

int rangesum(int i, int j)
{
	return sum(j)-sum(i-1);
}

void solve()
{
	for(int i=1;i<=N;++i){
		if(lst[c[i]]>0) add(lst[c[i]], -1);
		add(i,1);
		lst[c[i]]=i;
		for(int j=0;j<qry[i].size();++j){
			ans[qid[i][j]]=rangesum(qry[i][j],i);
		}
	}
	for(int i=0;i<Q;++i)cout<<ans[i]<<'\n';
}

int main()
{
	cin >> N >> Q;
	for(int i=1;i<=N;++i) cin >> c[i];
	for(int i=0;i<Q;++i){
		cin >> l[i] >> r[i];
		qry[r[i]].push_back(l[i]);
		qid[r[i]].push_back(i);
	}
	solve();
	return 0;
}


Measured memory_bytes: 56872
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int main(){
  int n;
  cin >> n;

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

  double bunbo=0;
  for(int i=0; i<n; i++) bunbo+=1/a[i];
  printf("%7lf\n", 1/bunbo);

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        int result = 0;
        
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        for (int i=1; i<=n; i++){
            int sum = 0;
            String str = Integer.toString(i);
            String []resultArray = str.split("");
            
            for(int j = 0; j < resultArray.length; j++){
                int num=Integer.parseInt(resultArray[j]);
                sum += num;
            }
            
            if(a <= sum && sum <= b){
                result += i;
            }
            
        }

        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 34516
#include <stddef.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s, t;
  while (getline(cin, s)) {
    t.clear();
    for (size_t i = 0; i < s.size(); i++)
      if (s.find("apple", i) == i) {
        t += "peach"; i += 4;
      }
      else if (s.find("peach", i) == i) {
        t += "apple"; i += 4;
      }
      else t += s[i];
    cout << t << endl;
  }
}

Measured memory_bytes: 1180
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int a, b, x;
	cin >> a >> b >> x;
	if (a > x)
		cout << "NO" << endl;
	else if (b >= x - a)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
} 

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

int main() {
	string S;
	cin >> S;
	int n = S.length();
	char before = 'R';
	vector<int> ans(n, 0);
	int odd = 0, even = 0;
	int odd_index = 0, even_index = 0;
	for (int i = 0; i < n; i++) {
		if (before == S[i]) (i % 2 == 0 ? even : odd)++;
		else {
			if (S[i]=='L') {
				odd_index = (i % 2 == 0 ? i - 1 : i);
				even_index = (i % 2 == 0 ? i : i - 1);
			}
			ans[odd_index] += odd;
			ans[even_index] += even;
			odd = i % 2 != 0;
			even = i % 2 == 0;
		}
		before = S[i];
	}
	ans[odd_index] += odd;
	ans[even_index] += even;
	for (int a : ans) cout << a << " ";
	cout << endl;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,i,a;
    cin>>n;
    i=a=0;
    int arr[n],brr[n],crr[n];
    while(i<n) {
      cin>>arr[i];
      i++;
    }
    i=0;
    while(i<n) {
      cin>>brr[i];
      crr[i]=arr[i]-brr[i];
      i++;
    }
    sort(crr,crr+n);
    i=n-1;
    while(crr[i]>0 && i>=0) {
      a+=crr[i];
      i--;
    }
    cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define e "\n"
#define MaRiaMa { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
#define fix(n) cout << fixed << setprecision(n);
using namespace std;
int main()
{
	MaRiaMa;
	int n, k,i=1,g=0;
	int j = 1;
	bool m = false;
	cin >> n >> k;
	while (g<n)
	{
		j = i;
		i *= 2;
		j += k;
		if (i > j)
		{
			break;
		}
		g++;
	}
	n -= g;
	i = 1;
	while (g!=0)
	{
		i *= 2;
		g--;
	}
	while (n != 0)
	{
		i += k;
		n--;
	}
	cout << i;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#define ll long long
using namespace std;

ll A[111111];
ll B[111111];
ll C[111111];

ll dp1[111111];
ll dp2[111111];

ll nA[111111];
ll nB[111111];
ll nC[111111];
int main() {
    ll X,Y,Z;
    cin>>X>>Y>>Z;
    for(int i=0;i<X+Y+Z;i++)
    {
        cin>>A[i]>>B[i]>>C[i];
    }
    
    
    vector<pair<ll,int> > diff_ids;
    for(int i=0;i<X+Y+Z;i++) {
        diff_ids.push_back(make_pair(C[i]-B[i],i));
    }
    
    sort(diff_ids.begin(),diff_ids.end());
    for(int i=0;i<X+Y+Z;i++) {
        nA[i]=A[diff_ids[i].second];
        nB[i]=B[diff_ids[i].second];
        nC[i]=C[diff_ids[i].second];
    }
    for(int i=0;i<X+Y+Z;i++) {
        A[i]=nA[i];
        B[i]=nB[i];
        C[i]=nC[i];
        diff_ids[i].second=i;
    }
    
    
    set<pair<ll,int> > fwd;
    ll summ = 0;
    for(int i=0;i<Y;i++) {
        int idd = diff_ids[i].second;
        fwd.insert(make_pair(B[idd]-A[idd],idd));
        summ += B[idd];
    }
    
    dp1[Y-1]=summ;
    
    
    
    for(int i=Y;i<X+Y;i++) {
        int idd = diff_ids[i].second;
        fwd.insert(make_pair(B[idd]-A[idd],idd));
        set<pair<ll,int> >::iterator topp = fwd.begin();
        summ += A[topp->second]-B[topp->second];
        summ += B[idd];
        fwd.erase(topp);
        dp1[i]=summ;
    
    }
    
    set<pair<ll,int> > bck;
    summ = 0;
    for(int i=X+Y+Z-1;i>=X+Y;i--) {
        int idd = diff_ids[i].second;
        bck.insert(make_pair(C[idd]-A[idd],idd));
        summ += C[idd];
    }
    
    dp2[X+Y]=summ;
    
    for(int i=X+Y-1;i>=Y;i--) {
        int idd = diff_ids[i].second;
        bck.insert(make_pair(C[idd]-A[idd],idd));
        set<pair<ll,int> >::iterator topp = bck.begin();
        summ += A[topp->second]-C[topp->second];
        summ += C[idd];
        bck.erase(topp);
        dp2[i]=summ;
        
    }
    
    // Z-1-(X-x)+1=Z-X+x=x+Y
    ll ans = 0;
    for(int x=0;x<=X;x++) {
        ans = max(ans, dp1[x+Y-1]+dp2[x+Y]);
    }
    
    cout << ans << endl;
    
    
    
    
}

Measured memory_bytes: 14704
#include<bits/stdc++.h>
using namespace std;
set<string>ma;
unordered_set<string>unset;
int letter[26];
bool judge(string s){
    int cont=0;
    memset(letter,0,sizeof(letter));
    string key;
    for(int i=0;i<s.size();i++){
        if(letter[s[i]-'a']==0){
            ++cont;
            letter[s[i]-'a']=cont;
            key.push_back('0'+cont);
        }else{
            key.push_back('0'+letter[s[i]-'a']);
        }
    }
    if(unset.find(key)==unset.end()){
        unset.insert(key);
        return true;
    }else{
        return false;
    }
}


void dfs(int loc,int n,string s){
    if(loc>n){
        if(judge(s)){
            ma.insert(s);
        }
        return;
    }
    for(int i=0;i<loc;i++){
        s.push_back('a'+i);
        dfs(loc+1,n,s);
        s.erase(s.end()-1);
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    string s="a";
    dfs(2,n,s);
    for(auto i=ma.begin();i!=ma.end();i++){
        cout<<(*i)<<endl;
    }
    return 0;
}


Measured memory_bytes: 24228
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=21;
const int MAXMASK=(1<<21);
int n,K;char ch[MAXMASK];
int f[MAXN][MAXMASK],bin[25],Log[MAXMASK];
int lowbit(int x){return x&-x;}
int gi(int x){return Log[lowbit(x)];}
vector<int> first_0[MAXN];
int rev(int T,int j)
{
	int ret=0;
	for(int i=1;i<=T;i++)ret|=bin[T-i+1]*((j&bin[i])>0);
	return ret;
}
bool check(int u1,int u2)
{
	for(int i=1;i<=n;i++)
	{
		int u=((u1&bin[i])>0),v=((u2&bin[i])>0);
		if(!u&&v)return true;
		if(u&&!v)return false;
	}return true;
}
int sum[MAXMASK];
int main()
{
	bin[1]=1;for(int i=2;i<25;i++)bin[i]=bin[i-1]<<1;
	for(int i=1;i<=21;i++)Log[bin[i]]=i;
	n=read();K=read();
	for(int i=0;i<=n;i++)
	{
		scanf("%s",ch);int len=strlen(ch);
		for(int j=0;j<len;j++)if(ch[j]=='1')
		f[i][rev(i,j)|bin[n+1]]=1;
	}
	for(int i=1;i<=n;i++)
	{
		first_0[i].resize(bin[i+1]);
		for(int j=0;j<bin[i+1];j++)
		for(int k=1;k<=i;k++)if(!(j&bin[k])){first_0[i][j]=k;break;}
	}
	int ans1=0,ans2=0;
	for(int i=n;i>=0;i--)for(int j=0;j<bin[n+2];j++)if(f[i][j])
	{
		int val=(bin[n+2]-1)^(bin[i+1]-1);
		int mask1=(j&(bin[i+1]-1)),mask2=(j&val),pos=gi(mask2);
		
		if(i)
		{
			int first_one=gi(mask1);
			if(first_one)
			{
				int u=i-first_one,v=mask1>>first_one;
				int id=mask2|bin[pos-1];v|=id;
				
				
				f[u][v]+=f[i][j];
			}
			
			int first_zero=first_0[i][mask1];
			if(first_zero)
			{
				int u=i-first_zero,v=mask1>>first_zero;
				int id=mask2^bin[pos]|bin[pos-1];v|=id;
				f[u][v]+=f[i][j];
//				if(u==0&&v==2)
//				{
//					int g;++g;
//				}
			}
		}
		
		mask2>>=pos;pos=n+1-pos;
//		if((rev(pos,mask2)|bin[pos+1])==4)
//		{
//			int t;++t;
//		}
		if(pos)sum[rev(pos,mask2)|bin[pos+1]]+=f[i][j];
	}
	for(int i=bin[n+2]-1;i>=1;i--)if(sum[i]>=K)
	{
		int mx=0;
		for(int j=n+1;j>=1;j--)if(i&bin[j]){mx=j;break;}
		if(mx-1>ans1)ans1=mx-1,ans2=i^bin[mx];
		else if(mx-1==ans1&&check(i^bin[mx],ans2))ans2=i^bin[mx];
	}
	for(int i=1;i<=ans1;i++)putchar(ans2&bin[i]?'1':'0');
	return 0;
}


Measured memory_bytes: 194944
#include <iostream>
#include <cmath>
#include <cstdio>


using namespace std;
typedef long long ll;

int main(){
  int A[3];
  for (int i = 0; i < 3; i++) {
    cin >> A[i];
  }

  int loc[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, {1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
  int min = 1000000;
  for (int i = 0; i < 6; i++) {
    int i0 = loc[i][0], i1 = loc[i][1], i2 = loc[i][2];
    int cost = fabs(A[i1] - A[i0]) +  fabs(A[i2] - A[i0]);
    if (cost < min) {
      min = cost;
    }
  }
  cout << min << endl;

}


Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int T = 1;
            while (T-- > 0)
            {
                solveOne(in, out);
            }
        }

        private void solveOne(Scanner in, PrintWriter out)
        {
            int N = in.nextInt(), X = in.nextInt(), T = in.nextInt();

            out.println((int) (Math.ceil((double) N / X) * T));
        }

    }
}



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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray()[1]-1;
            var S = Console.ReadLine();
            var result = "";
            for(var i = 0;i<S.Length;i++)
            {
                if(i==k)
                {
                    result += S[i].ToString().ToLower();
                    continue;
                }
                result += S[i];
            }
            Console.WriteLine(result);
        }
    }
}


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

int main(){
  string s,t;
  cin>>s>>t;
  bool b=false,c=true;
  
  
  for(int i=0;i<s.size();i++){
    if(s.at(i)!=t.at(i)){c=false;}
  }
  
  if((s.size()+1)==t.size()){b=true;}

  
  if(b&&c){cout<<"Yes";}
  else{cout<<"No";}
}

Measured memory_bytes: 3620
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

//vector//
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

typedef pair<int,int> P;  //q(p.first,p.second)

int main (){
    int n; cin  >> n;
    vector<char> c(n);
    for(int i=0; i<n; i++){
        cin >> c[i];
    }

    int left = 0;
    int right = n-1;
    int ans = 0;
    // 変更する必要がないときはok=1
    bool ok = 1;
    for(int i=0; i<n-1; i++){
        if(c[i]=='W' && c[i+1]=='R') ok = 0;
    }

    if(ok){
        cout << 0;
    }else{
        while(left<right){
            if(c[left]=='W' && c[right]=='R'){
                left++;
                right--;
                ans++;
            }else if(c[left]=='R'){
                left++;
            }else if(c[right]=='W'){
                right--;
            }else{;}
        }
        cout << ans;
    }
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    double pi = 3.141592653589793238462;
    int r;
    cin >> r;
    cout << 2 * pi * r << endl;
    return 0;
}

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

int main(){
    int N;
    long long t,res;
    cin >> N >> res;

    for (int i=0;i<N-1;i++){
        cin >> t;
        long long a,b,r=1;
        if (t > res){
            a = t;b=res;
        }
        else {
            a = res;b=t;
        }
        while (r > 0){
            r = a % b ;
            a = b;
            b = r;
        }
        res = res/a*t;
    }
    cout << res << endl;
}
    //sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});

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

int tree[200010];

int init(){
  for(int i = 0;i < 200010;i++){
    tree[i] = i;
  }
}

int root(int i){
  if(tree[i] == i) return i;
  return tree[i] = root(tree[i]);
}

void unite(int i, int j){
  i = root(i);
  j = root(j);
  if(i != j) tree[max(i, j)] = min(i, j);
}

bool same(int i, int j){
  return root(i) == root(j);
}

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

  init();

  for(int i = 0;i < n;i++){
    int k;
    cin >> k;
    for(int j = 0;j < k;j++){
      int tmp;
      cin >> tmp;
      tmp = (tmp-1) + 100005;
      unite(i, tmp);
    }
  }

  for(int i = 1;i < n;i++){
    if(!same(0, i)){
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;

  return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
char buf[20000];sz;
inline int rd()
{
	int ret=0;
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		ret=ret*10+k-'0';
	}
	return ret;
}
int d[3001];
const int mod=998244353;
main()
{
	read(0,buf,20000);
	int N=rd();
	int S=rd();
	int ans=0;
	for(int i=0;i<N;i++)
	{
		++d[S];
		for(int j=rd(),k=0;j<=S;j++,k++)
		{
			d[k]+=d[j];
			d[k]-=mod*(d[k]>=mod);
		}
		ans+=d[0];
		if(ans>=mod)ans-=mod;
	}
	printf("%d",ans);
}

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

struct Node{
    int val;
    Node* left;
    Node* right;
};
Node* nil;

class Tree{
    Node* root;
    void preorder(Node* p){
        if (p == nil) return;
        cout << " " << p->val;
        preorder(p->left);
        preorder(p->right);
    }
    void inorder(Node* p){
        if (p == nil) return;
        inorder(p->left);
        cout << " " << p->val;
        inorder(p->right);
    }
public:
    Tree(){
        root = nil;
    }
    void insert(int k){
        Node* n = new Node;
        n->val   = k;
        n->left  = nil;
        n->right = nil;
        if (root == nil) {
            root = n;
            return;
        }
        Node* pos = root;
        Node* pos_p;
        while (pos != nil) {
            pos_p = pos;
            if (k < pos->val) {
                pos = pos->left;
                continue;
            }
            pos = pos->right;
        }
        if (k < pos_p->val) {
            pos_p->left = n;
        } else {
            pos_p->right = n;
        }
    }
    void print(){
        inorder(root);
        cout << endl;
        preorder(root);
        cout << endl;
    }
};

int main(){
    int n;
    cin >> n;
    Tree T;
    for (int i = 0; i < n; i++) {
        string str;
        cin >> str;
        if (str == "insert") {
            int k;
            cin >> k;
            T.insert(k);
            continue;
        }
        T.print();
    }
    return 0;
}

Measured memory_bytes: 18612
#include<bits/stdc++.h>
using namespace std;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int n, r;
   cin >> n >> r;
   if(n<=10) {
       cout << r + 100*(10-n) << endl;
   } else {
       cout << r << endl;
   }
} 

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

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

signed main() {
    string s;
    ll k;
    cin>>s>>k;
    k--;

    ll t=0;
    rep(i,0,s.size()){
        if(s[i]=='1'){ 
            t++;
        }else{
            break;
        }
    }
    t--;

    // cout<<k<<" "<<t<<endl;
    if (k<=t) {
        cout<<1<<endl;
    } else {
        cout<<s[t+1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi a(n+2);
    a[0] = 0;
    rep(i, n) cin >> a[i+1];
    a[n+1] = 0;
    vi sm(n+2);
    rep(i, n+1) {
        sm[i+1] = sm[i] + abs(a[i+1] - a[i]);
    }
    for (int i = 1; i <= n; ++i) {
        int ans = sm[i-1] + abs(a[i+1] - a[i-1]) + (sm[n+1] - sm[i+1]);
        cout << ans << endl;
    }
}

Measured memory_bytes: 2048
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder.ABC113.A
{
    class Program
    {
        static void Main()
        {
            var sc = new Scanner();
            var x = sc.Nextint();
            var y = sc.Nextint();

            Console.WriteLine(x + y / 2);
        }
    }
    class Scanner
    {
        string[] s;
        long i;

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

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

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

        public int Nextint()
        {
            return int.Parse(Next());
        }
        public int[] Arrayint(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Nextint() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

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

        public double NextDouble()
        {
            return double.Parse(Next());
        }

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

        public decimal NextDecimal()
        {
            return decimal.Parse(Next());
        }

        public decimal[] ArrayDecimal(long N, decimal add = 0)
        {
            decimal[] Array = new decimal[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextDecimal();
            }
            return Array;
        }
    }
}


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

#define int long long
#define fi first
#define se second
#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 rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,ans,cnt[30000];
string s;
vector<int> v[10];
bool used[10];

void kr() {
    int c=0;
    bool hoge[10]={};
    repm(i,s.size()) {
        cnt[i] = c;
        if (!hoge[s[i]-'0']) {
            hoge[s[i]-'0'] = true;
            c++;
        }
    }
}

signed main() {
    cin >> n;
    cin >> s;
    kr();
    rep(i,s.size()) v[s[i]-'0'].pb(i);
    rep(i,10) v[i].pb(INF);
    rep(i,s.size()) {
        if (!used[s[i]-'0']) {
            used[s[i]-'0'] = true;
            rep(j,10) {
                int idx = *upper_bound(all(v[j]),i);
                if (idx == INF) continue;
                ans += cnt[idx];
            }
        }
    }
    cout << ans << endl;
}





Measured memory_bytes: 1024
# https://atcoder.jp/contests/abc131/tasks/abc131_c

import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

def main():
    A, B, C, D = map(int, input().split())

    CD = C * D // gcd(max(C, D), min(C, D))
    # A 未満で C, D で割り切れる個数
    ac_div = (A - 1) // C
    ad_div = (A - 1) // D

    acd_div = (A - 1) // CD
    a_total = ac_div + ad_div - acd_div

    # B 以下で C, D で割り切れる個数
    bc_div = B // C
    bd_div = B // D

    bcd_div = B // CD
    b_total = bc_div + bd_div - bcd_div

    # B - A から割り切れる個数を引く
    ans = B - A + 1 - (b_total - a_total)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]

x, y = map(int, input().split())

if x is 2 or y is 2:
    print("No")
elif x in a and y in a:
    print("Yes")
elif x in b and y in b:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3316
n, m = map(int, input().split())

a_list = [0 for i in range(m)]
for i in range(n):
    for i in map(int, input().split()[1:]):
        a_list[i-1] = a_list[i-1] + 1

count = 0
for item in a_list:
    if item == n:
        count += 1

print(count)


Measured memory_bytes: 2940
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#else
    //    freopen("zalupa.in","r",stdin);
    //    freopen("zalupa.out","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(20);
    cout << fixed;
    int a;
    cin >> a;
    int b;
    cin >> b;
    if (a == 1 && b == 1) {
        cout << 1000000;
        return 0;
    }
    int res = 0;
    if (a == 1) {
        res += 300000;
    }
    if (a == 2) {
        res += 200000;
    }
    if (a == 3) {
        res += 100000;
    }
    if (b == 1) {
        res += 300000;
    }
    if (b == 2) {
        res += 200000;
    }
    if (b == 3) {
        res += 100000;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	if (b >= a)
		cout << "unsafe" << endl;
	else
		cout << "safe" << endl;
	return 0;
}

Measured memory_bytes: 3132
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	N = int(input())
	
	if N <= 999:
		print("ABC")
	else:
		print("ABD")
	
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 13212
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + 100*j + 50*k == x:
                ans += 1

print(ans)


Measured memory_bytes: 67836
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

int n, m;
int a[1010], b[1010], c[1010];
int d[110][110];
int pre[110][110];

const int INF = 1e7;

void init(int n){
    rep(i, 0, n){
        rep(j, 0, n){
            d[i][j] = INF;
            pre[i][j] = i;
            if(i == j) d[i][j] = 0;
        }
    }
}

void warshall_floyd(){
    rep(k, 0, n){
        rep(i, 0, n){
            rep(j, 0, n){
                if(d[i][k] + d[k][j] < d[i][j]){
                    d[i][j] = d[i][k] + d[k][j];
                    pre[i][j] = pre[k][j];
                }
            }
        }
    }
}

int f[110][110];

void path(int s, int g){
    vector<int> pt;
    for(int i = g; i != s; i = pre[s][i]){
        // st.insert(i);
        pt. push_back(i);
    }
    reverse(all(pt));
    int now = s;
    rep(i, 0, pt.size()){
        f[now][pt[i]] = true;
        now = pt[i];
    }
}

signed main(){
    cin >> n >> m;
    init(n);
    rep(i, 0, m){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        d[a[i]][b[i]] = c[i];
        d[b[i]][a[i]] = c[i];
    }
    warshall_floyd();
    rep(i, 0, n) rep(j, 0, n) f[i][j] = false; 
    rep(i, 0, n){
        rep(j, i + 1, n){
            path(i, j);
        }
    }
    int ans = 0;
    rep(i, 0, m){
        if(f[a[i]][b[i]] == false && f[b[i]][a[i]] == false) ans++;
    }
    o(ans);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int n;
int a[200000], b[200000];

int main(){
  cin >> n;
  rep(i, n) cin >> a[i] >> b[i];
  sort(a, a+n); sort(b, b+n);
  if(n%2) cout << b[n/2] - a[n/2] + 1 <<endl;
  else cout << (b[n/2-1] + b[n/2]) - (a[n/2-1] + a[n/2]) + 1 <<endl;
}
  
    

Measured memory_bytes: 5192
def main():
    x1, y1, x2, y2 = map(int, input().split())
    xx = abs(y1 - y2)
    yy = abs(x1 - x2)
    if x1 > x2:
        if y1 > y2:
            print(x2 + xx, y2 - yy, x1 + xx, y1 - yy)
        else:
            print(x2 - xx, y2 - yy, x1 - xx, y1 - yy)
    else:
        if y1 > y2:
            print(x2 + xx, y2 + yy, x1 + xx, y1 + yy)
        else:
            print(x2 - xx, y2 + yy, x1 - xx, y1 + yy)


main()


Measured memory_bytes: 3060
N = int(input())
H = list(map(int, input().split(" ")))
M = 0
i = 0

while i < (N - 1):
    m = 0
    j = i
    if (M > N - i):
        break
    while j < (N - 1):
        if H[j] >= H[j+1]:
            m = m + 1
            j = j + 1
        else:
            break
    M = max(M, m)
    i = j + 1

print(M)



Measured memory_bytes: 14252
fn solve() {
    let s: Vec<char> = read::<String>().chars().collect();
    let t: Vec<char> = read::<String>().chars().collect();
    let mut ans = 0;
    for i in 0..s.len() {
        if s[i] != t[i] {
            ans += 1;
        }
    }
    println!("{:?}", ans);
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Reverse};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


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

int main() {
  string sa, sb, sc;
  cin >> sa >> sb >> sc;
  
  int a = 0, b = 0, c = 0;
  char now = 'a';
  while(a <= sa.size() && b <= sb.size() && c <= sc.size()){
    if(a == sa.size() && now == 'a'){
      cout << "A" << endl;
      break;
    }
    else if(b == sb.size() && now == 'b'){
      cout << "B" << endl;
      break;
    }
    else if(c == sc.size() && now == 'c'){
      cout << "C" << endl;
      break;
    }
    else if(now == 'a'){
      now = sa.at(a);
      a++;
    }
    else if(now == 'b'){
      now = sb.at(b);
      b++;
    }
    else{
      now = sc.at(c);
      c++;
    }
  }
}

Measured memory_bytes: 256
S = input()
Q = int(input())
queries = [input().split() for i in range(Q)]

head = []
tail = []
forward = True
for query in queries:
    if query[0] == '1':
        forward = not forward
    else:
        if query[1] == '1' and forward or query[1] == '2' and not forward:
            head.append(query[2])
        else:
            tail.append(query[2])

if forward:
    ans = ''.join(head[::-1]) + S + ''.join(tail)
else:
    ans = ''.join(tail[::-1]) + S[::-1] + ''.join(head)
print(ans)


Measured memory_bytes: 45304
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Spandan Mishra
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CReplacingInteger solver = new CReplacingInteger();
        solver.solve(1, in, out);
        out.close();
    }

    static class CReplacingInteger {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.readLong();
            long k = in.readLong();
//        System.out.println(n % k + " " + (k - (n % k)));
            long ans = Math.min(n % k, k - (n % k));

            System.out.println(ans);

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new RuntimeException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 20820
"use strict";
    
const div = (a, b) => Math.floor(a / b);

const main = arg => {
    arg = arg.trim().split("\n");
    const D = parseInt(arg[0].split(" ")[0]);
    const G = parseInt(arg[0].split(" ")[1]);
    
    const scores = arg.slice(1, D + 1);
    
    let p = [];
    let c = [];
    
    for(let i=0; i<D; i++) {
        let temp = scores[i].split(" ").map(n=>parseInt(n));
        p[i] = temp[0];
        c[i] = temp[1];
    }
    
    let ans = 1e9;
    
    for (let mask = 0; mask < (1 << D); ++mask) {
        let s = 0, num = 0, rest_max = -1;
        
        for (let i = 0; i < D; ++i) {
            if (mask >> i & 1) {
                s += 100 * (i + 1) * p[i] + c[i];
                num += p[i];
            } else rest_max = i;
        }
        
        if (s < G) {
            let s1 = 100 * (rest_max + 1);
            let need = div(G - s + s1 - 1, s1);
            if (need >= p[rest_max]) continue;
            num += need;
        }
        
        ans = Math.min(ans, num);
    }
    
    console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False

def cost(x, y, initial, N):
    a = x[initial]
    b = y[initial]
    for i in range(N):
        if i == initial:
            continue

    return 0


def main():
    N = I()
    x = [0] * N
    y = [0] * N
    ans = 0
    dist = [[None] * N for i in range(N)]

    if N == 1:
        print(1)
        return

    for i in range(N):
        x[i], y[i] = MI()

    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            dist[i][j] = str(x[j] - x[i]) + "," + str(y[j] - y[i])

    # print_matrix(dist)

    c = defaultdict(int)
    ans = 1
    for i in range(N):
        for j in range(N):
            if dist[i][j] == None:
                continue
            c[dist[i][j]] += 1

    mcost = max(c.values())
    print(N - mcost)


if __name__ == '__main__':
    main()


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

int n, m;
int resultwin[100000], resultlose[100000];
bool graph[5001][5001];
int graphlose[5001];
bool ansflag = false;
vector<int> ansvector;

int main()
{
  cin >> n >> m;
  for(int i = 0; i < m; i++)
    cin >> resultwin[i] >> resultlose[i];

  for(int i = 0; i < m; i++){
    graphlose[resultlose[i]]++;
    graph[resultlose[i]][resultwin[i]] = true;
  }

  for(int i = 0; i < n; i++){    
    int win = 0;
    for(int j = 1; j <= n; j++){
      if(!graphlose[j]){
	if(win)
	  ansflag = true;
	win = j;
      }
    }

    ansvector.push_back(win);
    graphlose[win] = -1;
    for(int j = 1; j <= n; j++){
      if(graph[j][win])
	graphlose[j]--;
    }
  }

  for(int i = 0; i < n; i++)
    cout << ansvector[i] << endl;

  cout << (ansflag ? 1 : 0) << endl;

  return 0;
}

Measured memory_bytes: 26488
#include<cstdio>
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
int a[401000],in[401000];
int h[401000],q[401000],nxt[401000],to[401000],K=0;
bool b[401000];int c[401000];
int ri[401000],len=0;
vector<int> v[401000];
void ins(int u,int v){nxt[++K]=h[u];h[u]=K;to[K]=v;}
int getsg(int u)
{
	for(int i=h[u];i;i=nxt[i])
		if(in[to[i]]<=0)b[a[to[i]]]=1;
	if(b[0]==0)return 0;
	for(int i=1;i<=200000;i++)if(!b[i])return i;
}
void Memset(int u)
{
	for(int i=h[u];i;i=nxt[i])
		if(in[to[i]]<=0)b[a[to[i]]]=0;
}
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int p;scanf("%d",&p);ins(i,p);ins(p,i);in[p]++; 
		v[p].push_back(i);
	}
	int H=0,T=0;
	for(int i=1;i<=n;i++)if(!in[i])q[T++]=i,a[i]=0;
	while(H<T)
	{
		int u=q[H++];a[u]=getsg(u);Memset(u);
		for(int i=h[u];i;i=nxt[i])
		{
			in[to[i]]--;
			if(in[to[i]]==0)q[T++]=to[i];
		}
	}
	for(int i=1;i<=n;i++)if(in[i]==1){ri[++len]=i;}
	memset(h,0,sizeof(h));K=0;
	for(int i=1;i<=len;i++)
	{
		int SIZ=v[ri[i]].size();
		for(int j=0;j<SIZ;j++)ins(ri[i],v[ri[i]][j]);
	}
	for(int i=2;i<=len;i++)
	{
		for(int j=h[ri[i-1]];j;j=nxt[j])if(in[to[j]]==1){ri[i]=to[j];break;}
	}
	memset(in,0,sizeof(in));
	for(int i=1;i<=n;i++)c[i]=a[i];
	int o;in[ri[2]]++;a[ri[1]]=getsg(ri[1]);o=a[ri[1]];Memset(ri[1]);in[ri[2]]--;
	for(int i=len;i>=2;i--)
	{
		a[ri[i]]=getsg(ri[i]);Memset(ri[i]);
	}
	if(a[ri[2]]!=a[ri[1]]){puts("POSSIBLE");return 0;}
	for(int i=1;i<=n;i++)a[i]=c[i];
	a[ri[2]]=o;a[ri[1]]=getsg(ri[1]);Memset(ri[1]);
	for(int i=len;i>=3;i--)
	{
		a[ri[i]]=getsg(ri[i]);Memset(ri[i]);
	}
	if(getsg(ri[2])==o){puts("POSSIBLE");return 0;}
	puts("IMPOSSIBLE");
	return 0;
}//缩成一个环和环往外连的几个点 ，对于环上某一个点， 要么它取mex，要么它前一个点取mex 

Measured memory_bytes: 27008
S = input()
N = len(S)
ans = []

def cal(R_count, L_count, ans):
    ans += [0] * (R_count-1)   # 中央の'RL'以外は全て0
    ans.append((R_count+1)//2 + (L_count//2))
    ans.append((L_count+1)//2 + (R_count//2))
    ans += [0] * (L_count-1)   # 中央の'RL'以外は全て0

R_count, L_count, i = 0, 0, 0
while i<N:
    if S[i]=='R':
        R_count += 1
        i += 1
    else:
        while i<N and S[i]=='L':
            L_count += 1
            i += 1
        cal(R_count, L_count, ans)
        R_count, L_count = 0, 0

print(*ans)

Measured memory_bytes: 6424
#include <stdio.h>
int main(void);

int main(void){
    
    int a, b, c;
    int min, max, mid;
    scanf("%d %d %d", &a, &b, &c);    
    
    if(a <= b){
        
        min = a;
        max = b;
        
        if(b <= c){
            
            mid = b;
            max = c;
            
        } else if(a <= c){
            
            mid = c;
            
        } else {
            
            min = c;
            mid = a;
            
        }
    } else {
        
        min = b;
        max = a;
        
        if(a <= c){
            
            mid = a;
            max = c;
            
        } else if(b <= c){
            
            mid = c;
            
        } else {
            
            min = c;
            mid = b;
            
        }
    }
    
    printf("%d %d %d\n", min, mid, max);
    
    return 0;
    
}



Measured memory_bytes: 2028
//ksun48 code - just to mark ac
#include <bits/stdc++.h>
using namespace std;


int main(){
	int n, m;
	cin >> n >> m;
	vector<int> deg(n, 0);
	vector<vector<int> > edges(n);
	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		a--; b--;
		deg[a]++; deg[b]++;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	for(int i = 0; i < n; i++){
		if(deg[i] & 1){
			cout << "No" << '\n';
			exit(0);
		}
	}
	for(int i = 0; i < n; i++){
		if(deg[i] >= 6){
			cout << "Yes" << '\n';
			exit(0);
		}
	}
	int d4 = 0;
	for(int i = 0; i < n; i++){
		if(deg[i] >= 4) d4++;
	}
	if(d4 >= 3){
		cout << "Yes" << '\n';
		exit(0);
	} else if(d4 == 2){
		vector<int> d4s;
		for(int i = 0; i < n; i++) if(deg[i] == 4) d4s.push_back(i);
		int v = d4s[0];
		int w = d4s[1];
		int npaths = 0;
		for(int x : edges[v]){
			int cur = x;
			int p = v;
			while(cur != v && cur != w){
				assert(int(edges[cur].size()) == 2);
				p = edges[cur][0] + edges[cur][1] - p;
				swap(p, cur);
			}
			if(cur == w) npaths++;
		}
		if(npaths == 2){
			cout << "Yes" << '\n';
		} else if(npaths == 4){
			cout << "No" << '\n';
		}
	} else if(d4 <= 1){
		cout << "No" << '\n';
		exit(0);
	}
}


Measured memory_bytes: 6144