akhauriyash/Code-Regression huggingface dataset:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
x=0
for i in range(0,n-1):
  if a[i]+1==a[i+1]:
    x+=c[a[i]-1]
y=sum(b)
print(x+y)

Measured memory_bytes: 3064
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int max = 0;
	int t = 0;
	for (int i = 0; i < s.length(); i++) {
		switch (s[i]){
		case 'A':
		case 'T':
		case 'C':
		case 'G':
			i++;
			t = 1;
			while (i < s.length()) {
				if (s[i] == 'A') {
					i++;
					t++;
				}
				else if (s[i] == 'T') {
					i++;
					t++;
				}
				else if (s[i] == 'G') {
					i++;
					t++;
				}
				else if (s[i] == 'C') {
					i++;
					t++;
				}
				else {
					break;
				}
			}
			break;
		}

		if (max < t) {
			max = t;
		}
	}
	cout << max << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
flag = 1
for num in a:
    if num % 2 == 0:
        if (num % 3 == 0) or (num % 5 == 0):
            flag = 1
        else:
            flag = 0
            break
print('APPROVED') if flag else print('DENIED')

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


int main() {
    int n;
    while (cin >> n && n>0) {
       int sum,L,M,s;
       L = 0;
       M = 1000;
       sum = 0;
       for (int i=0;i<n;i++) {
            cin >> s;
            if (s>L) L=s;
            if (s<M) M=s;
            sum += s; 
       }
       sum -= L+M;
       sum /= n-2;
       cout << sum << endl;  
       }
}



Measured memory_bytes: 3080
#include <stdio.h>

int main(){
  int A, B, C;

  scanf("%d%d%d", &A, &B, &C);

  for(int i = 1; i <= B; i++){
    if((A*i)%B == C){
      printf("YES\n");
      return 0;
    }
  }

  printf("NO\n");
  
  return 0;
}

/*
正の整数 A, B, C に対し，
  A*i = C (mod B)
を満たす自然数 i (1 <= i <= B) は存在するか?
*/


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

int f(int a){
  if(a%2==0)
    return a/2;
  else
    return 3*a+1;
}

int main(){
  int s; cin>>s;
  int j=0,i=0,c=0;
  
  if(s==1) cout<<4<<endl;
  else if(s==2) cout<<4<<endl;
  else{
  	while(c != 2){
    	if(s==4) c += 1;
    	s = f(s);
    	i++;
  	}
  	cout<<i<<endl;
  }
  return 0;
}
   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;
using P = pair<int, int>;

int main(){
    int n, w; cin >> n >> w;
    P a[n+1];
    loop(i, 1, n+1) cin >> a[i].first >> a[i].second;

    int dp[n+1][w+1];
    memset(dp, 0, sizeof(dp));
    loop(i, 1, n+1){
        loop(j, 1, w+1){
            if(j - a[i].second >= 0) dp[i][j] = max(dp[i-1][j], dp[i-1][j-a[i].second] + a[i].first);
            else dp[i][j] = dp[i-1][j];
        }
    }
    cout << dp[n][w] << endl;

    return 0;
}


Measured memory_bytes: 7024
import math
N = int(input())
def isPrime(n):
  if n < 2:
    return False
  i = 2
  while i*i <= n:
    if n%i == 0:
      return False
    i += 1
  return True
if isPrime(N):
  print(len(str(N)))
else:
  ans = float("inf")
  i = 1
  while i <= math.sqrt(N):
    if N % i == 0:
      if i >= N // i:
        ans = min(ans,len(str(i)))
      else:
        ans = min(ans,len(str(N // i)))
    i += 1
  print(ans)    

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

struct Query {
  int index;
  int l, r;
};

// Supports two operations.
// - Updates a single element.
// - Returns a sum of a range.
// Verified: CF573Div1D
class BinaryIndexedTree {
 private:
  int n;
  vector<int64> xs;
 public:
  BinaryIndexedTree(int n) : n(n), xs(n) {}

  // Adds x to the i-th element.
  void Add(int i, int64 x) {
    int cur = i;
    while (cur < n) {
      xs[cur] += x;
      cur = cur | (cur + 1);
    }
  }

  // Returns a sum of a range [l, r).
  int64 SumRange(int l, int r) {
    if (l >= r) return 0;
    if (l > 0) {
      return SumRange(0, r) - SumRange(0, l);
    }
    int64 s = 0;
    int i = r - 1;
    while (i >= 0) {
      s += xs[i];
      i = (i & (i + 1)) - 1;
    }
    return s;
  }
};

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

  int n;
  int q;
  cin >> n >> q;
  vector<int> cs(n);
  for (int i = 0; i < n; i++) {
    cin >> cs[i];
    cs[i]--;
  }
  vector<vector<Query>> r_to_qs(n);
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    r_to_qs[r].push_back({i, l, r});
  }

  vector<int> last_pos_vector(n, -1);
  
  BinaryIndexedTree tree(n);
  
  vector<int64> ans(q);
  for (int r = 0; r < n; r++) {
    int c = cs[r];
    int p = last_pos_vector[c];
    last_pos_vector[c] = r;
    if (p >= 0) {
      tree.Add(p, -1);
    }
    tree.Add(r, 1);
    for (const auto& q : r_to_qs[r]) {
      int64 v = tree.SumRange(q.l, q.r + 1);
      ans[q.index] = v;
    }
  }
  for (int i = 0; i < q; i++) {
    cout << ans[i] << "\n";
  }
}


Measured memory_bytes: 38016
import numpy
import math

def main():
  n = int( input() )
  
  x = []
  y = []
  
  for i in range(n):
    x_tmp, y_tmp = (int(x) for x in input().split())
    
    x.append( x_tmp )
    y.append( y_tmp )
  
  cnt = 0.0
  
  for i in range(n):
    for j in range(i,n):
      distance = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])
      cnt = cnt + (math.sqrt( distance ) * (n-1))
  
  waru = 0
  
  for i in range(n):
    waru = waru + i
  
  #cnt = cnt / math.factorial(n)
  cnt = cnt / waru
  
  print( cnt )

if __name__ == '__main__': main()

Measured memory_bytes: 12500
#include<bits/stdc++.h>
using namespace std;
int main(){
    string vec[4],s;int i;
    vec[0]="Sunny",vec[1]="Cloudy",vec[2]="Rainy",vec[3]="Sunny";
    cin>>s;
    for(i=0;i<3;i++){
        if(s==vec[i])
            cout<<vec[i+1];
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    int c0=0,c1=0,c2=0,c3=0;
    rep(i,n){
        if(s[i]=="AC") c0++;
        else if(s[i]=="WA") c1++;
        else if(s[i]=="TLE") c2++;
        else if(s[i]=="RE") c3++;
    }
    cout << "AC x " << c0 << endl;
    cout << "WA x " << c1 << endl;
    cout << "TLE x " << c2 << endl;
    cout << "RE x " << c3 << endl;
}

Measured memory_bytes: 6420
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n;
  cin>>n;
  rep(i,n,1000){
    string x=to_string(i);
    if(x[0]==x[1] && x[1]==x[2]){
      cout<<x<<endl;
      return;
    }
  }
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3676
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		ArrayDeque<Integer> stack = new ArrayDeque<>();

		while ( sc.hasNext() ) {
			int n = sc.nextInt();
			switch (n) {
			case 0:
				System.out.println( stack.pop() );
				break;
			default:
				stack.push(n);
				break;
			}
		}
	}

}

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

int main() {
    string N ;
    cin >> N ;
    
    vector<int> A(N.size()) ;
    
    for( int i=0 ; i<N.size() ; i++){
        A.at(i) = (N.at(i)-48) ;
    }
    
    int cnt=0 ;
    
    for( int i=0 ; i< A.size() ; i++){
        cnt+= A.at(i) ;
    }
    
    if( cnt%9==0 || cnt == 0 ){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 4360
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
x,k,d = readInts()
ikeru = abs(x)//d
# 0 の時も忘れないでね～
#print(ikeru)
if ikeru >= k:
    if x > 0:
        print(abs(x - k*d))
    elif x < 0:
        print(abs(x + (k*d)))
else:
    # ikeru <= k
    if ikeru%2 == k%2:
        if x > 0:
            print(x - (ikeru*d))
        else:
            print(abs(x+(ikeru*d)))
    else:
        if x > 0:
            print(abs(x - (ikeru*d) - d))
        else:
            print(abs((abs(x+(ikeru*d)) - d)))


Measured memory_bytes: 10412
#include <bits/stdc++.h>
using namespace std;
#define int long long
int INF = 1e9+7;
signed main() {
    int N,A,B;
    cin >> N >> A >> B;
    vector<int>P(N);
    int cnt = 0;
    int cnt2 = 0;
    int cnt3 = 0;
    for(int i = 0; i < N; i++) {
        cin >> P[i];
        if(P[i] > A && P[i] <= B) {
            cnt++;
        }
        else if(P[i] <= A) {
            cnt2++;
        }
        else {
            cnt3++;
        }
    }
    cout << min(min(cnt,cnt2),cnt3) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int i, j, d;
  while(scanf("%d", &d) != EOF){
    int sum = 0, c = 1;
    while(1){
      if ((c * d) > (600 - d)) break;
      sum += c * d * c * d * d;
      c++;
    }
    printf("%d\n", sum);
  }

  return 0;
}

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
   if(A+B == C+D){
     cout << "Balanced" << endl;
   }else if(A+B > C+D){
     cout << "Left" << endl;
   }else {
     cout << "Right" << endl;
   }
}

Measured memory_bytes: 256
n = int(input())
S = [input() for _ in range(n)]
d_S = dict()
for s in S:
    d_S[s] = d_S.get(s, 0) + 1
max_v = max(d_S.values())
most_S = []
for s in d_S.items():   
    if ( s[1] == max_v):
        most_S.append(s[0])
for s in sorted(most_S):
    print(s)

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

int main() {
  
  string S;
  cin >> S;
  
  if(S[0] != 'A'){ cout << "WA" << endl; return 0; }
  
  bool C =false;
  int large=0;
  
  for(int i=0; i<S.size(); i++){
    if(isupper(S[i])){ large+=1; }
  }
  
  for(int i=2; i<S.size()-1; i++){
    if(S[i]=='C'){ C=true; }
  }
  
  if(C && large==2){ cout << "AC" << endl; }
  else{ cout << "WA" << endl; }

  
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<queue>
#include <tuple>
#include <cassert>
#define int long long
using namespace std;
char maze[2134][2134];
pair <int, int> iti[2134];
signed main() {
	int a, w, b, ans = 0; cin >> a >> w >> b;
	const int INF = 1000000000; typedef pair<int, int>P;
	for (int h = 1; h <= a; h++) {
		for (int i = 1; i <= w; i++) {
			cin >> maze[h][i];
			if (maze[h][i] == 'S') { iti[0].first = h; iti[0].second = i; }
			if (maze[h][i] == '1') { iti[1].first = h; iti[1].second = i; }
			if (maze[h][i] == '2') { iti[2].first = h; iti[2].second = i; }
			if (maze[h][i] == '3') { iti[3].first = h; iti[3].second = i; }
			if (maze[h][i] == '4') { iti[4].first = h; iti[4].second = i; }
			if (maze[h][i] == '5') { iti[5].first = h; iti[5].second = i; }
			if (maze[h][i] == '6') { iti[6].first = h; iti[6].second = i; }
			if (maze[h][i] == '7') { iti[7].first = h; iti[7].second = i; }
			if (maze[h][i] == '8') { iti[8].first = h; iti[8].second = i; }
			if (maze[h][i] == '9') { iti[9].first = h; iti[9].second = i; }
		}
	}
	for (int h = 0; h < b; h++) {
		int sx = iti[h].first, sy = iti[h].second, gx = iti[h + 1].first, gy = iti[h + 1].second;
		int d[1234][1234], dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
		queue<P> que;
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= w; j++) {
				d[i][j] = INF;
			}
		}
		que.push(P(sx, sy));
		d[sx][sy] = 0;
		while (que.size()) {
			P p = que.front(); que.pop();
			if (p.first == gx && p.second == gy) {
				break;
			}
			for (int i = 0; i < 4; i++) {
				int nx = p.first + dx[i], ny = p.second + dy[i];
				if (0 < nx && nx <= a && 0 < ny && ny <= w && maze[nx][ny] != 'X' && d[nx][ny] == INF) {
					que.push(P(nx, ny));
					d[nx][ny] = d[p.first][p.second] + 1;
				}
			}
		}
		ans += d[gx][gy];
	}
	cout << ans << endl;
}


Measured memory_bytes: 14884
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;
#define int long long

signed main() {
  int n, k;
  cin >> n >> k;
  int x[n], y[n];
  int xcpy[n], ycpy[n];
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    xcpy[i] = x[i];
    ycpy[i] = y[i];
  }
  sort(x, x + n);
  sort(y, y + n);
  int ans = LLONG_MAX;
  for (int xl = 0; xl < n; xl++) {
    for (int xr = xl + 1; xr < n; xr++) {
      for (int yl = 0; yl < n; yl++) {
        for (int yr = yl + 1; yr < n; yr++) {
          int count = 0;
          for (int i = 0; i < n; i++) {
            if (x[xl] <= xcpy[i] && xcpy[i] <= x[xr] && y[yl] <= ycpy[i] && ycpy[i] <= y[yr]) {
              count++;
            }
          }
          if (count >= k) {
            int res = (x[xr] - x[xl]) * (y[yr] - y[yl]);
            ans = min(ans, res);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int i,x,y;

	while(1){
		scanf("%d %d",&x,&y);
		if(x!=0||y!=0){
			if(x>y){
				i=x;
				x=y;
				y=i;
			}
			printf("%d %d\n",x,y);
		}else{
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 600
A,B,C,X,Y = map(int,input().split())
if X<=Y:
    ans = X*min(A+B,2*C)
    ans += (Y-X)*min(B,2*C)
else:
    ans = Y*min(A+B,2*C)
    ans += (X-Y)*min(A,2*C)
print(ans)

Measured memory_bytes: 61784
n=int(input())
from collections import deque
def dfs():
  todo=deque([[1]])
  ret=[]
  while len(todo)>0:
    t=todo.popleft()
    if len(t)==n:
      ret.append(t)
    else:
      l=max(t)+1
      for i in range(l):
        tc=t.copy()
        tc.append(i+1)
        todo.append(tc)
  return ret
a=dfs()
n2a = lambda c: chr(c+64).lower()
for ai in a:
  #print(ai)
  print(''.join(map(n2a,ai)))


Measured memory_bytes: 30264
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main(){
  int n,m;
  cin >> n>>m;
  int a = min(n,m);
  int b = max(n,m);
  rep(i,0,b){
      cout << a ;
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
n, m = map(int,input().split())
k, s = [], []
for i in range(m):
  inp = list(map(int, input().split()))
  k_, s_ = inp[0], inp[1:]
  k.append(k_)
  s.append(s_)
p = list(map(int, input().split()))
ans = 0
for bit in range(1<<n):
  flg = True
  for i in range(m):
    cnt = 0
    for e in s[i]:
      e -= 1
      if bit & 1<<e: cnt += 1
    if cnt%2 != p[i]: flg = False
  if flg: ans += 1
print(ans)

Measured memory_bytes: 9052
X = gets.to_i
a5 = [0]
a = 1
loop{
    a5 << a ** 5
    warn a5[-1]
    break if a5[-1] - a5[-2] >= X
    a += 1
}
r = nil
a5.size.times{|a|
    a5.size.times{|b|
        if a5[a] - a5[b] == X
            r = [a, b]
            break
        end
        if a5[a] + a5[b] == X
            r = [a, -b]
            break
        end
    }
    break if r
}
puts r * " "


Measured memory_bytes: 14304
#include<iostream>

using namespace std;

int main(void){
    int a = 0, b = 0;
    cin >> a >> b;
    if(a > b)
        cout << "a > b" << endl;
    else if(a == b)
        cout << "a == b" << endl;
    else
        cout << "a < b" << endl;
}


Measured memory_bytes: 3096
#include "iostream"
#include "cstdio"
#include "cstring"
#include "string"
#include "cmath"
#include "algorithm"
#include "map"
#include "set"
#include "vector"
#define eps 1e-6
using namespace std;
const int maxn=55;
double s[maxn];
long long c[maxn][maxn];
int n,a,b;
bool cmp(double x,double y){
	return x>y;
}
void init(){
	c[0][0]=1;
	for(int i=1;i<=n;i++){
		c[i][0]=1,c[i][i]=1;
		for(int j=1;j<i;j++)
			c[i][j]=c[i-1][j-1]+c[i-1][j];
	}
}
int main()
{
	while(cin>>n>>a>>b){
		init();
		for(int i=0;i<n;i++)
			cin>>s[i];
		sort(s,s+n,cmp);
		double sum=0;
		for(int i=0;i<a;i++){
			sum+=s[i];
		}
		double h=sum/(double)a;
		int x=0,y=0;
		for(int i=0;i<n;i++)
			if(s[i]==s[a-1]){
				x++;
				if(i<a)
					y++;
			}
		//cout<<x<<" "<<y<<endl;
		printf("%.6f\n",h);
		if(s[0]!=s[a-1]){
			cout<<c[x][y]<<endl;
		}else{
			long long cnt=0;
			for(int i=a;i<=min(b,x);i++)
				cnt+=c[x][i];
			cout<<cnt<<endl;
		}
		//printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int N, K;

    cin >> N >> K;

    int a = 0;
    int b = K;
    while ( 1 ) {
        a ++;
        if ( N < b ) break;
        b *= K;
    }

    cout << a << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int maxCount = 0, count = 0;
    for (int i = 0; i < S.length(); i++) {
      if (S.charAt(i) == 'A' || S.charAt(i) == 'T' || S.charAt(i) == 'G' || S.charAt(i) == 'C') {
        count++;
        if (count > maxCount) {
            maxCount = count;
        }
      }
      else count = 0;
    }
    System.out.println(maxCount);
  }
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int> time(N);
  for(int i=0;i<N;i++)cin>>time.at(i);
  int M;cin>>M;
  int P,X;
  int a=accumulate(time.begin(),time.end(),0);
  int sum;
  for(int i=0;i<M;i++){
    sum=a;
    cin>>P>>X;
    sum=sum-time.at(P-1)+X;
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define xx first
#define yy second
#define MP make_pair
#define pb push_back
#define ll long long

using namespace std;

void yes()
{
    cout <<"Yes"<<endl;return;

}
void no(){
cout << "No"<<endl;return;
}

void YES()
{
    cout <<"YES"<<endl;return;

}
void NO(){
cout << "NO"<<endl;return;
}


int main()
{
     int t;

	  ll a,b,c,d;
	  cin >>a>>b>>c>>d;

	  ll e = a*c;
	  ll f = a*d;
	    ll g = b*c;
	   ll h = b*d;
	   ll ans = max(e,f);
	   ans= max(ans,g);
	   ans = max(ans,h);
	   cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main(){
	const int INF = 1010101010;
	
	int n;
	cin >> n;
	vector<int> as(n), bs(n);
	for(int &x : as){ cin >> x; }
	for(int &x : bs){ cin >> x; }

	int p2n = 1 << n;
	vector<vector<int>> dp(p2n, vector<int>(51, INF));
	dp[0][0] = 0;
	for(int S = 0; S < p2n; ++S){
		for(int j = 1; j <= 50; ++j){
			dp[S][j] = min(dp[S][j], dp[S][j - 1]);
		}
		int ord = __builtin_popcount(S);
		for(int j = 0; j < n; ++j){
			if(S >> j & 1){ continue; }
			int val = abs(ord - j) & 1 ? bs[j] : as[j];
			int cost = __builtin_popcount(S >> j);
			int &r = dp[S | 1 << j][val];
			r = min(r, dp[S][val] + cost);
		}
	}
	int ans = *min_element(dp.back().begin(), dp.back().end());
	if(ans >= INF){ ans = -1; }
	cout << ans << '\n';
}


Measured memory_bytes: 63744
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<string, pair<ll,ll> >
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 59;
ll i,j,x,y,n,k,a,b,g,ans;
ll v[N], p[N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>k;
    rep(i,1,n + 1) cin>>v[i];
    for(i = 0;i <= n;i += 1) for(x = 0;x <= i;x += 1){
        a = 0;
        if(i > 0){
            for(g = 1;g <= i;g += 1){
                a += v[g];
                p[g] = v[g];
            }
            sort(p + 1,p + i + 1);
            for(g = 1;g <= x;g += 1) a -= p[g];
        }
        for(j = n + 1;j > i;j -= 1) for(y = 0;y <= n - j + 1;y += 1){
            b = 0;
            if(j <= n){
                for(g = n;g >= j;g -= 1){
                    b += v[g];
                    p[n - g + 1] = v[g];
                }
                sort(p + 1,p + n - j + 1 + 1);
                for(g = 1;g <= y;g += 1)
                    b -= p[g];
            }
            if(i + x + n - j + 1 + y <= k)
                ans = max(ans, a + b);
        }
    }
    cout<<ans;
    return 0;
} 

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

int main(int argc, const char * argv[]) {
    int N;
    int max_count = 0;
    int ans = 0;
    
    cin >> N;
    for (int i = 1; i <= N; i++) {
        int num = i;
        int count = 0;
        while (num > 0) {
            num /= 2;
            count++;
        }
        if (max_count < count) {
            max_count = count;
            ans = i;
        }
        max_count = max(max_count, count);
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

char lower[] = "abcdefghijklmnopqrstuvwxyz";
char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(void)
{
    int i;
    char c;

    while(1) {
        scanf("%c", &c);
        if(c == '\n') break;

        for(i=0;i<26;i++) {
            if(c == lower[i]) c = upper[i];
            else if(c == upper[i]) c = lower[i];
        }
        printf("%c", c);
    }

    putchar('\n');

    return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define VFOR(x,a,b) for(int x=(a);x<((a)+(b));x++)
ll F(string N, int K);
int main(){
  string N; int K;
  cin >> N >> K;
  cout << F(N,K);
  return 0;
}
ll F(string N, int K){
  if(K==0) return 1;
  if(N.size()<K) return 0;
  if(N.size()==0) return 0;
  if(N.size()==1) return (N[0]-'0');
  string s9,sl;
  VFOR(i,0,N.size()-1) {
    s9 += '9';
  }
  VFOR(i,1,N.size()-1){
    if(N[i]!= '0'){
      while(i<N.size()){
        sl += N[i];
        i++;
      }
      i = -10;
    }
  }
  ll ans=( F(s9,K)+(N[0]-'0'-1)*F(s9,K-1)+F(sl,K-1) );
  //cout << "F( " << N << ", " << K << ") = " << ans << endl;
  return ( ans );
}

Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<string>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
char aho[3] = { '+', '-', '*' };
int main()
{
	char s[150];
	int x;
	stack<int> stk;
	while (scanf("%s", s) != EOF)
	{
		if (s[0] == '+')
		{
			int h = stk.top();
			stk.pop();
			h += stk.top();
			stk.pop();
			stk.push(h);
		}
		else if (s[0] == '-')
		{
			int h = stk.top();
			stk.pop();
			int j = stk.top();
			stk.pop();
			h = j - h;
			stk.push(h);
		}
		else if (s[0] == '*')
		{
			int h = stk.top();
			stk.pop();
			h *= stk.top();
			stk.pop();
			stk.push(h);
		}
		else { 
			x = atoi(s);
			stk.push(x);
		}
	}
	cout << stk.top()<<endl; return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define N 100010
using namespace std;
typedef unsigned long long ull;
ull const Base = 1777771;
int n,par[N],in[N];

ull bfs(){
  queue<int> Q;
  ull ans=0;
  map<ull,int> M[N];
  vector<ull> H(n,1),dep(n,0);
  for(int i=0;i<n;i++)if(!in[i])Q.push(i),ans+=M[0][1]++;
  
  while(!Q.empty()){
    int pos = Q.front();Q.pop();
    int nx = par[pos];
    ull &A = H[pos],&B = H[nx];
    dep[nx] = max(dep[nx],dep[pos]+1);
    B+=A*Base;
    if(--in[nx]==0)ans+=M[dep[nx]][B]++,Q.push(nx);
  }
  return ans;
}

int main(){
  cin>>n;
  for(int i=0,a,b;i<n-1;i++){
    cin>>a>>b;
    in[a-1]++,par[b-1] = a-1;
  }
  cout<<bfs()<<endl;
  return 0;
}

Measured memory_bytes: 15980
import java.io.PrintWriter;
import java.util.*;

public class Main {

    private static long gcd(long a, long b) {
        if (a == 0) return b;
        return gcd(b % a, a);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        String s = in.next();
        out.println(solve(s) ? "Yes" : "No");

        out.flush();
    }

    private static boolean solve(String s) {
        if ("ABC".equals(s)) return true;
        int n = s.length(), step = 0;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            char c = s.charAt(i);
            sb.append(c);
            if (c == 'A') {
                step = 1;
            } else if (step == 1 && c == 'B') step = 2;
            else if (step == 2 && c == 'C') {
                step = 0;
                sb.setLength(sb.length() - 3);
                sb.append('X');
            }
        }
        String ns = sb.toString();
        if (!ns.contains("X")) return false;
        if (/* !ns.contains("BX") && !ns.contains("XB") && */!ns.contains("B")) {
            String r = ns.replace('X', 'B');
            if (solve(r)) {
                //System.err.println(r);
                return true;
            }
        }
        if (/*!ns.contains("XC") &&*/ !ns.contains("A")) {
            String r = ns.replace('X', 'A');
            if (solve(r)) {
                //System.err.println(r);
                return true;
            }
        }
        if (/*!ns.contains("AX") && */!ns.contains("C")) {
            String r = ns.replace('X', 'C');
            if (solve(r)) {
                //System.err.println(r);
                return true;
            }
        }
        return false;
    }

}



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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
 int a , b ;
  cin >> a >> b ;
  if(a>b)
    cout << "safe" ;
  else 
    cout << "unsafe";


}


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

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

using namespace std;

typedef pair<int,int> ii;
string s;

int main(){
  getline(cin,s);
  deque<ii> ans;
  deque<int> deq;
  rep(i,s.size()){
    if( s[i] == '\\' ) deq.push_back(i);
    else if( s[i] == '/' && !deq.empty() ){
      int sp = deq.back(); deq.pop_back();
      int area = i - sp;
      while( !ans.empty() && sp <= ans.back().first ){
	area += ans.back().second;
	ans.pop_back();
      }
      ans.push_back(ii(sp,area));
    }
  }
  int sum = 0;
  rep(i,ans.size()) sum += ans[i].second;
  cout << sum << endl << (int)ans.size();
  rep(i,ans.size())cout << ' ' << ans[i].second; puts("");
  return 0;
}


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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[],int n){
    for(int i=0;i<n;i++){
    cout<<a[i]<<" ";
    }
    cout<<endl;
}
int disum(int n){
	int sum=0;

	while(n){

		sum+=n%10;
		n/=10;





	}
	return sum;




}
int main() {
    int i,n,m,k,c=0,sum=0;
    c_p_c();
    cin>>n;
    for (int i = 1; i <=n; i+=2)
    {
    	/* code */


    	// watch(i);

    	int no_of_divisor=2;
    	for (int j = 2; j < i-1; j++)
    	{
    		/* code */
    		if(i%j==0) {
    			no_of_divisor++;

    			// watch(j);
    		}
    	}
    	// watch(no_of_divisor);
    	if(no_of_divisor==8){
    		c++;
    		// watch(i);	
    	} 



    }
    cout<<c<<endl;


}



Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
const int maxn = 10000 + 10;

int main(){
    int n;
    cin >> n;
    int sum = 0, N = n;
    while(n){
        sum += n % 10;
        n /= 10;
    }
    if(N % sum == 0) cout << "Yes" << "\n";
    else cout << "No" << "\n";
    return 0;
}


Measured memory_bytes: 256
const MOD: usize = 1e9 as usize + 7;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let h: usize = sc.read();
    let w: usize = sc.read();
    if w == 1 {
        println!("1");
        return;
    }
    let k: usize = sc.read();
    let mut dp = vec![0; w];
    dp[0] = 1;
    for _ in 0..h {
        let mut next = vec![0; w];
        for mask in 0..(1 << (w - 1)) {
            if (0..(w - 2)).any(|i| mask & (1 << i) != 0 && mask & (1 << (i + 1)) != 0) {
                continue;
            }
            for pos in 0..w {
                let is_left = (1 << pos) & mask != 0;
                let is_right = pos > 0 && (1 << (pos - 1)) & mask != 0;
                let next_pos = if is_left {
                    pos + 1
                } else if is_right {
                    pos - 1
                } else {
                    pos
                };
                next[next_pos] += dp[pos];
                next[next_pos] %= MOD;
            }
        }
        dp = next;
    }
    println!("{}", dp[k - 1]);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#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()
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 h, w, a, b;
    cin >> h >> w >> a >> b;
    rep(i, h) {
        rep(j, w) {
            if (i < b && j < a) {
                cout << 0;
            } else if (i < b) {
                cout << 1;
            } else if (j < a) {
                cout << 1;
            } else {
                cout << 0;
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 1280
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,Q;
long long m;
#define Maxn 100010
int head[Maxn],v[Maxn<<1],nxt[Maxn<<1],tot=0;
int bel[Maxn],col=0;
inline void add_edge(int s,int e){
	tot++;v[tot]=e;nxt[tot]=head[s];head[s]=tot;
	tot++;v[tot]=s;nxt[tot]=head[e];head[e]=tot;
}
void dfs(int u){
	bel[u]=col;
	for(int i=head[u];i;i=nxt[i])
	    if(!bel[v[i]])dfs(v[i]);
}

struct P{
	int a,b;
}seq[Maxn];
int len=0;

int main(){
	scanf("%d%lld%d",&n,&m,&Q);
	int a,b,c;
	for(register int i=1;i<=Q;++i){
		scanf("%d%d%d",&a,&b,&c);
		a++;b++;
		if(!c)add_edge(a,b);
		else seq[++len]=(P){a,b};
	}
	for(register int i=1;i<=n;++i)
	    if(!bel[i]){
			col++;
			dfs(i);
	    }
	for(register int i=1;i<=len;++i)
	    if(bel[seq[i].a]==bel[seq[i].b]){
			puts("No");
			return 0;
	    }
	m-=n-(col);
	if(m<0){
		puts("No");
		return 0;
	}
	if(len){
		if(m>=max(3,col)&&m<=1ll*col*(col-1)/2)puts("Yes");
		else puts("No");
	}else{
		if(m<=1ll*col*(col-1)/2&&m>=col-1)puts("Yes");
		else puts("No");
	}
	return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <queue>
#include<map>
#include<algorithm>
#include<set>
#include<iomanip>
#include<string>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<=n;i++)
#define rrep(i,n) for(int i = n-1;i >=0;i--)
#define ALL(a) a.begin(),a.end()
#define PI  acos(-1)
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
typedef long long int ll;
typedef long double ld;
const int MOD = 1e9 + 7;
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 }, sum = 0, h, w;
int main() {
    int n, a; cin >> n; vector<int> p(100, 0);
    rep(i, n) {
        cin >> a;
        rrep(j, a) p[j]++;
    }
    rrep(i, 100) {
        if (i + 1 <= p[i]) {
            cout << i + 1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> A;
  for(int i = 0; i < N; ++i) {
    int a; cin >> a;
    A.push_back(a);
  }
  
  int sum = accumulate(A.begin(), A.end(), 0);

  int cnt = count_if(A.begin(), A.end(), [sum, M](int x){ return sum <= (x * 4 * M); });

  if(M <= cnt)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, abc):
    dp = [0] * 3
    for i in range(1, n + 1):
        a, b, c = abc[i - 1]
        dp = [ max(dp[1] + a, dp[2] + a), \
               max(dp[0] + b, dp[2] + b), \
               max(dp[0] + c, dp[1] + c) ]
    return(max(dp))

n = int(input())    # 1 <= n <= 10^5
abc = [list(map(int, input().rstrip().split())) for _ in range(n)]

print(f(n, abc))


Measured memory_bytes: 30580
h, w = map(int, raw_input().strip().split())
grid = [[0 for i in xrange(w)] for j in xrange(h)]

for i in xrange(h):
    grid[i] = list(raw_input().strip())

idxl = [[-1 for i in xrange(h * w)] for j in xrange(4)]

# for left
for i in xrange(h):
    left = -1
    for j in xrange(w):
        if grid[i][j] == '#': left = j
        idxl[0][i * w + j] = left

# for right
for i in xrange(h):
    right = w
    for j in xrange(w - 1, -1, -1):
        if grid[i][j] == '#': right = j
        idxl[1][i * w + j] = right

# for up
for j in xrange(w):
    up = -1
    for i in xrange(h):
        if grid[i][j] == '#': up = i
        idxl[2][i * w + j] = up

# for down
for j in xrange(w):
    down = h
    for i in xrange(h - 1, -1, -1):
        if grid[i][j] == '#': down = i
        idxl[3][i * w + j] = down

ans = 0
for i in xrange(h):
    for j in xrange(w):
        if grid[i][j] == '#': continue
        k = i * w + j
        left = j - idxl[0][k]
        right = idxl[1][k] - j
        up = i - idxl[2][k]
        down = idxl[3][k] - i
        cur = left + right + up + down - 3
        ans = max(ans, cur)

print ans

Measured memory_bytes: 333856
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def tm(a, b, hi, wi):
	lb=len(b[0])
	for i, bi in enumerate(b):
		if a[hi+i][wi: wi+lb] != bi:
			return False
	return True
	


def main():
	#a = int(input())
	n, m = tin()
	#s = input()
	al=[input() for _ in range(n)]
	bl=[input() for _ in range(m)]
	for hi in range(n-m+1):
		for wi in range(n-m+1):
			if tm(al, bl, hi, wi):
				return 'Yes'
	return 'No'
	
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 9272
import sys
sys.setrecursionlimit(10**7)

N=int(input())
Graph=[[] for _ in range(N)]
color=[-1]*N

for _ in range(N-1):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    Graph[a].append((b,c))
    Graph[b].append((a,c))

def dfs(Graph,v,cur=0):
    global color
    color[v]=cur
    for next_v_t in Graph[v]:
        next_v=next_v_t[0]
        w=next_v_t[1]
        if color[next_v]!=-1:
            continue
        ncur=cur
        if w%2==1:
            ncur=1-cur
        dfs(Graph,next_v,ncur)

#探索
for v in range(N):
    if color[v]==-1:
        dfs(Graph,v)
for i in color:
    print(i)


Measured memory_bytes: 88752
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
		int n; cin >> n;
		vector<int> a(n + 1);
		vector<int> b(n + 1);
		rep (i, n) {
			cin >> a[i + 1];
		}
		for (int i = n; i >= 1; --i) {
			int sum = 0;
			for (int j = i + i; j <= n;  j += i) {
				sum ^= b[j];
			}
			b[i] = sum^a[i];
		}
		vector<int> ans;
		repn (i, n) {
			if (b[i]) {
				ans.emplace_back(i);	
			}
		}
		cout << ans.size() << endl;
		rep (i, ans.size()) {
			cout << ans[i] << endl;
		}
    return;
}

int main() {
    solve();
    return 0;
}



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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long

template<typename T> inline constexpr auto square(T x) { return (x) * (x); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const int MOD = 1000000007;
const int INF = INT_MAX;

signed main()
{
	string S;
	cin >> S;

	sort(All(S));

	bool test = (S[0] == S[1]) && (S[1] != S[2]) && (S[2] == S[3]);

	if (test) COL("Yes");
	else COL("No");

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define INF 10000

int main(){
	int n;
	while(cin>>n,n){
		vector<string> s(n);
		set<string> s_set;
		for(auto&i:s)cin>>i;
		rep(i,n){
			bool ok=true;
			rep(j,n) ok&=(i==j or s[j].find(s[i])==-1);
			if(ok) s_set.insert(s[i]);
		}
		s.clear();
		for(auto&i:s_set)s.push_back(i);
		n=s.size();
		
		vvi a(n,vi(n,0));
		rep(i,n)rep(j,n){
			if(i==j) {
				a[i][j]=INF;
				continue;
			}
			int si=s[i].size(), sj=s[j].size();
			for(int p=min(si,sj)-1;p>0;p--){
				if(s[i].substr(si-p) == s[j].substr(0,p)){
					a[i][j]=-p; break;
				}
			}
		}
		vvi dp(1<<n,vi(n,INF));
		rep(i,n) dp[1<<i][i]=0;

		rep(st,(1<<n)){
			rep(i,n) if(dp[st][i]!=INF) rep(j,n){
				if(st & (1<<j))  continue;
				int next=st|(1<<j);
				int cost=dp[st][i]+a[i][j];
				dp[next][j]=min(dp[next][j], cost);
			}
		}
		
		int ans=*min_element(all(dp[(1<<n)-1]));
		for(auto i:s)ans+=i.size();
		cout<<ans<<endl;
	}
	return 0;
}



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

using namespace std;
int main(){
  string S;
  string T;
  cin >> S;
  cin >> T;
  int a=0;
  for(int i=0;i<3;++i){
    if(S.at(i)==T.at(i)){
      a++;
    }
  }
   cout<<a<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
bool isprime(int a){
    if(a <= 1)return false;
    for(int i = 2;i * i <= a;i++){
        if(a % i == 0)return false;
    }
    return true;
}
main(){
    int accum[100010] = {};
    rep(i,1,100001){
        if(i % 2 && isprime(i) && isprime((i+1)/2)){
            accum[i] = 1;
        }
    }
    rep(i,1,100001){
        accum[i] += accum[i-1];
    }
    int Q;
    cin >> Q;
    rep(i,0,Q){
        int l,r;
        cin >> l >> r;
        cout << accum[r] - accum[l-1] << endl;
    }    
}

Measured memory_bytes: 1024
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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 (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N; cin >> N;
	VI A(N), B(N);
	bool F = true;
	int sum = 0;
	REP(i, N) {
		cin >> A[i] >> B[i];
		sum += A[i];
		if (A[i] != B[i])F = false;
	}
	
	if (F) {
		cout << 0 << endl;
		return 0;
	}
	
	int ans = LLINF;
	
	REP(i, N) {
		
		if (A[i] > B[i])chmin(ans, B[i]);
	}

	cout << sum - ans << endl;

	return 0;
}



Measured memory_bytes: 768
using System;

namespace A___Changing_a_Character
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            var N = read[0];
            var K = read[1];
            string S = Console.ReadLine();
            String result = "";
            for(int i = 0 ; i < N ; i++)
            {
                if(i == K-1)
                {
                    result += S[i].ToString().ToLower();
                }else{
                    result += S[i];
                }
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13140
/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.!!!*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define T int t = 1; cin>>t; while(t--)
#define ain int n,k,i; cin>>n>>k; int a[n]; for(i=0;i<n;i++) cin>>a[i]
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1]; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define I insert
#define pb push_back

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;
inline ll add(ll a, ll b) { return (mod + a + b) % mod;}
inline ll sub(ll a, ll b) {return (a - b + mod) % mod;}
inline ll mul(ll a, ll b) {return (1ll * a * b) % mod;}
ll fastpow(ll x, ll y) {
    ll res = 1; x = x % mod; while (y > 0) { if(y & 1) res = (res * x) % mod; y = y >> 1;x = (x * x) % mod;}return res;}
ll inv(ll x) {
    return fastpow(x, mod - 2);
}



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    ain;
    
    sort(a,a + n);
    
    int price = 0;
    for(i = 0;i < k;++i)
        price += a[i];
    
    cout << price;
    
    
    
    
    
}

Measured memory_bytes: 3648